From 02a7063a0922c6c59a9f71ea2627e4f211a79899 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 26 Mar 2011 08:13:42 +0000 Subject: fix for blenderplayer crashing on exit. 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 | 11 ++++++++++- intern/ghost/GHOST_ISystem.h | 9 ++++++++- intern/ghost/intern/GHOST_C-api.cpp | 7 +++++++ intern/ghost/intern/GHOST_System.cpp | 11 +++++++++++ intern/ghost/intern/GHOST_System.h | 7 ++++++- source/gameengine/GamePlayer/ghost/GPG_ghost.cpp | 4 ++++ 6 files changed, 46 insertions(+), 3 deletions(-) diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h index e1464542ed3..be8dc138797 100644 --- a/intern/ghost/GHOST_C-api.h +++ b/intern/ghost/GHOST_C-api.h @@ -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 ***************************************************************************************/ diff --git a/intern/ghost/GHOST_ISystem.h b/intern/ghost/GHOST_ISystem.h index 7e1300d780a..38c732153d7 100644 --- a/intern/ghost/GHOST_ISystem.h +++ b/intern/ghost/GHOST_ISystem.h @@ -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 ***************************************************************************************/ diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp index 20caa057be0..28058c60499 100644 --- a/intern/ghost/intern/GHOST_C-api.cpp +++ b/intern/ghost/intern/GHOST_C-api.cpp @@ -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; diff --git a/intern/ghost/intern/GHOST_System.cpp b/intern/ghost/intern/GHOST_System.cpp index ce492c2903b..559fb65277d 100644 --- a/intern/ghost/intern/GHOST_System.cpp +++ b/intern/ghost/intern/GHOST_System.cpp @@ -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) { diff --git a/intern/ghost/intern/GHOST_System.h b/intern/ghost/intern/GHOST_System.h index 1f2199855fa..b5c64bfceb6 100644 --- a/intern/ghost/intern/GHOST_System.h +++ b/intern/ghost/intern/GHOST_System.h @@ -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 diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp index 65a68f1bac3..968d6caeb1c 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp @@ -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); -- cgit v1.2.3