fix for blenderplayer crashing on exit.
authorCampbell Barton <ideasman42@gmail.com>
Sat, 26 Mar 2011 08:13:42 +0000 (08:13 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 26 Mar 2011 08:13:42 +0000 (08:13 +0000)
the event consumer was being freed twice, once when going out of C++ scope, another when freeing the system.

intern/ghost/GHOST_C-api.h
intern/ghost/GHOST_ISystem.h
intern/ghost/intern/GHOST_C-api.cpp
intern/ghost/intern/GHOST_System.cpp
intern/ghost/intern/GHOST_System.h
source/gameengine/GamePlayer/ghost/GPG_ghost.cpp

index e1464542ed31910ff9f3613b4e4e1d577c3c15b1..be8dc138797d1f9b8a028ccacc47ccb9e74cc140 100644 (file)
@@ -262,7 +262,16 @@ extern int GHOST_DispatchEvents(GHOST_SystemHandle systemhandle);
  */
 extern GHOST_TSuccess GHOST_AddEventConsumer(GHOST_SystemHandle systemhandle,
                                                                                          GHOST_EventConsumerHandle consumerhandle);
-       
+
+/**
+ * Remove the given event consumer to our list.
+ * @param systemhandle The handle to the system
+ * @param consumerhandle The event consumer to remove.
+ * @return Indication of success.
+ */
+extern GHOST_TSuccess GHOST_RemoveEventConsumer(GHOST_SystemHandle systemhandle,
+                                                                                         GHOST_EventConsumerHandle consumerhandle);
+
 /***************************************************************************************
  ** Progress bar functionality
  ***************************************************************************************/
index 7e1300d780ab5eb1407bfb992c12727c6d7b8ec4..38c732153d79c201aeb97f770023f3ef52bd23a2 100644 (file)
@@ -290,7 +290,14 @@ public:
         * @return Indication of success.
         */
        virtual GHOST_TSuccess addEventConsumer(GHOST_IEventConsumer* consumer) = 0;
-       
+
+       /**
+        * Removes the given event consumer to our list.
+        * @param consumer The event consumer to remove.
+        * @return Indication of success.
+        */
+       virtual GHOST_TSuccess removeEventConsumer(GHOST_IEventConsumer* consumer) = 0;
+
         /***************************************************************************************
         ** N-degree of freedom device management functionality
         ***************************************************************************************/
index 20caa057be01c4df311428b31965de6286fc8546..28058c604999c9b2d92edbf45fbb96ee5c5ba947 100644 (file)
@@ -253,6 +253,13 @@ GHOST_TSuccess GHOST_AddEventConsumer(GHOST_SystemHandle systemhandle, GHOST_Eve
        return system->addEventConsumer((GHOST_CallbackEventConsumer*)consumerhandle);
 }
 
+GHOST_TSuccess GHOST_RemoveEventConsumer(GHOST_SystemHandle systemhandle, GHOST_EventConsumerHandle consumerhandle)
+{
+       GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
+
+       return system->removeEventConsumer((GHOST_CallbackEventConsumer*)consumerhandle);
+}
+
 GHOST_TSuccess GHOST_SetProgressBar(GHOST_WindowHandle windowhandle,float progress)
 {
        GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
index ce492c2903b16eacfc2b3a808a053d53b062a861..559fb65277d871030b82b70e0d4c65fca2d15268 100644 (file)
@@ -226,6 +226,17 @@ GHOST_TSuccess GHOST_System::addEventConsumer(GHOST_IEventConsumer* consumer)
        return success;
 }
 
+GHOST_TSuccess GHOST_System::removeEventConsumer(GHOST_IEventConsumer* consumer)
+{
+       GHOST_TSuccess success;
+       if (m_eventManager) {
+               success = m_eventManager->removeConsumer(consumer);
+       }
+       else {
+               success = GHOST_kFailure;
+       }
+       return success;
+}
 
 GHOST_TSuccess GHOST_System::pushEvent(GHOST_IEvent* event)
 {
index 1f2199855fad909c5de8c40d30bc0a87575e3390..b5c64bfceb672a5efd716d4337a9cbac2f22d428 100644 (file)
@@ -183,7 +183,12 @@ public:
         */
        virtual GHOST_TSuccess addEventConsumer(GHOST_IEventConsumer* consumer);
 
-
+       /**
+        * Remove the given event consumer to our list.
+        * @param consumer The event consumer to remove.
+        * @return Indication of success.
+        */
+       virtual GHOST_TSuccess removeEventConsumer(GHOST_IEventConsumer* consumer);
 
        /***************************************************************************************
         ** N-degree of freedom devcice management functionality
index 65a68f1bac35e721b3b05bfb2a619837ad966704..968d6caeb1c0e1581e85b19964949ae647909b2e 100644 (file)
@@ -939,6 +939,10 @@ int main(int argc, char** argv)
                                                }
                                                app.StopGameEngine();
 
+                                               /* 'app' is freed automatic when out of scope. 
+                                                * removal is needed else the system will free an already freed value */
+                                               system->removeEventConsumer(&app);
+
                                                BLO_blendfiledata_free(bfd);
                                        }
                                } while (exitcode == KX_EXIT_REQUEST_RESTART_GAME || exitcode == KX_EXIT_REQUEST_START_OTHER_GAME);