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.
This commit is contained in:
Campbell Barton
2011-03-26 08:13:42 +00:00
parent d53a0cd48f
commit 02a7063a09
6 changed files with 46 additions and 3 deletions

View File

@@ -263,6 +263,15 @@ 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
***************************************************************************************/

View File

@@ -291,6 +291,13 @@ public:
*/
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
***************************************************************************************/

View 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;

View 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)
{

View 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

View 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);