Index: plugins/engine/3d/engine.h
===================================================================
--- plugins/engine/3d/engine.h	(revision 25072)
+++ plugins/engine/3d/engine.h	(working copy)
@@ -201,12 +201,8 @@
  * This class manages all components which comprise a 3D world including
  * sectors, polygons, curves, mesh objects, etc.
  */
-class csEngine : public scfImplementationExt4<csEngine,
-                                              csObject,
-                                              iEngine,
-                                              iComponent,
-                                              iPluginConfig,
-                                              iDebugHelper>
+class csEngine : public scfImplementationExt5<csEngine, csObject,
+  iEngine, iComponent, iPluginConfig, iDebugHelper, iEventHandler>
 {
   // friends
   friend class csLight;
@@ -572,28 +568,11 @@
   virtual bool SetOption (int id, csVariant* value);
   virtual bool GetOption (int id, csVariant* value);
 
+  // -- iEventHandler
   bool HandleEvent (iEvent &Event);
 
-  // -- iEventHandler
-  struct eiEventHandler : public scfImplementation1<
-  	eiEventHandler,iEventHandler>
-  {
-    csWeakRef<csEngine> parent;
-    eiEventHandler (csEngine* parent) : scfImplementationType (this)
-    {
-      eiEventHandler::parent = parent;
-    }
-    virtual ~eiEventHandler ()
-    {
-    }
-    virtual bool HandleEvent (iEvent& ev)
-    {
-      if (parent) return parent->HandleEvent (ev);
-      else return false;
-    }
-    CS_EVENTHANDLER_NAMES("crystalspace.engine.3d")
-    CS_EVENTHANDLER_NIL_CONSTRAINTS
-  } * scfiEventHandler;
+  CS_EVENTHANDLER_NAMES("crystalspace.engine.3d")
+  CS_EVENTHANDLER_NIL_CONSTRAINTS
 
   // -- iDebugHelper
   
@@ -996,6 +975,7 @@
   CS_DECLARE_SYSTEM_EVENT_SHORTCUTS;
   csEventID CanvasResize;
   csEventID CanvasClose;
+  csHandlerID weakHandler;
 };
 
 #endif // __CS_ENGINE_H__
Index: plugins/engine/3d/engine.cpp
===================================================================
--- plugins/engine/3d/engine.cpp	(revision 25072)
+++ plugins/engine/3d/engine.cpp	(working copy)
@@ -529,23 +529,20 @@
   clearZBuf (false), defaultClearZBuf (false), 
   clearScreen (false),  defaultClearScreen (false), 
   defaultMaxLightmapWidth (256), defaultMaxLightmapHeight (256),
-  currentRenderContext (0)
+  currentRenderContext (0), weakHandler(CS_HANDLER_INVALID)
 {
   DG_TYPE (this, "csEngine");
 
-  scfiEventHandler = new eiEventHandler (this);
-
   ClearRenderPriorities ();
 }
 
 csEngine::~csEngine ()
 {
-  if (scfiEventHandler)
+  if (weakHandler != CS_HANDLER_INVALID)
   {
     csRef<iEventQueue> q (CS_QUERY_REGISTRY (objectRegistry, iEventQueue));
     if (q != 0)
-      q->RemoveListener (scfiEventHandler);
-    scfiEventHandler->DecRef ();
+      RemoveWeakListener (q, objectRegistry, weakHandler);
   }
 
   DeleteAll ();
@@ -620,7 +617,7 @@
     // discard canvas events if there is no canvas, by truncating the array
     if (!G2D) events[2] = CS_EVENTLIST_END;
 
-    q->RegisterListener (scfiEventHandler, events);
+    RegisterWeakListener (q, this, events);
   }
 
   csConfigAccess cfg (objectRegistry, "/config/engine.cfg");
