From c6d0be2a9943818b98db3831e5d56969bd95c5fa Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 16 Sep 2008 19:25:35 +0000 Subject: Fix (harmless) error print about GameLogic.globalDict being lost. Also fixed some memory leaks in this code and simplified it. --- .../GamePlayer/ghost/GPG_Application.cpp | 29 ++++++++++++++-------- .../gameengine/GamePlayer/ghost/GPG_Application.h | 23 ----------------- source/gameengine/GamePlayer/ghost/GPG_ghost.cpp | 18 +------------- 3 files changed, 20 insertions(+), 50 deletions(-) (limited to 'source/gameengine/GamePlayer/ghost') diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp index 580c80ee0a5..752b776beff 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp @@ -115,6 +115,7 @@ GPG_Application::GPG_Application(GHOST_ISystem* system) m_cursor(GHOST_kStandardCursorFirstCursor), m_engineInitialized(0), m_engineRunning(0), + m_isEmbedded(false), m_ketsjiengine(0), m_kxsystem(0), m_keyboard(0), @@ -128,8 +129,7 @@ GPG_Application::GPG_Application(GHOST_ISystem* system) m_blendermat(0), m_blenderglslmat(0), m_pyGlobalDictString(0), - m_pyGlobalDictString_Length(0), - m_isEmbedded(false) + m_pyGlobalDictString_Length(0) { fSystem = system; } @@ -138,6 +138,12 @@ GPG_Application::GPG_Application(GHOST_ISystem* system) GPG_Application::~GPG_Application(void) { + if(m_pyGlobalDictString) { + delete m_pyGlobalDictString; + m_pyGlobalDictString = 0; + m_pyGlobalDictString_Length = 0; + } + exitEngine(); fSystem->disposeWindow(m_mainWindow); } @@ -680,7 +686,8 @@ bool GPG_Application::startEngine(void) initPythonConstraintBinding(); initMathutils(); - /* Restore the dict */ + // Set the GameLogic.globalDict from marshal'd data, so we can + // load new blend files and keep data in GameLogic.globalDict loadGamePythonConfig(m_pyGlobalDictString, m_pyGlobalDictString_Length); m_sceneconverter->ConvertScene( @@ -718,13 +725,15 @@ bool GPG_Application::startEngine(void) void GPG_Application::stopEngine() { - // get the python dict and convert to a string for future use - char *marshal_buffer; - m_pyGlobalDictString_Length = saveGamePythonConfig(&marshal_buffer); - if (m_pyGlobalDictString_Length) { - m_pyGlobalDictString = static_cast (malloc(m_pyGlobalDictString_Length)); - memcpy(m_pyGlobalDictString, marshal_buffer, m_pyGlobalDictString_Length); - } + // GameLogic.globalDict gets converted into a buffer, and sorted in + // m_pyGlobalDictString so we can restore after python has stopped + // and started between .blend file loads. + if(m_pyGlobalDictString) { + delete m_pyGlobalDictString; + m_pyGlobalDictString = 0; + } + + m_pyGlobalDictString_Length = saveGamePythonConfig(&m_pyGlobalDictString); // when exiting the mainloop exitGamePythonScripting(); diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.h b/source/gameengine/GamePlayer/ghost/GPG_Application.h index 7fc369fc0fd..38408f919b4 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.h +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.h @@ -74,29 +74,6 @@ public: bool StartGameEngine(int stereoMode); void StopGameEngine(); - char* - GetPyGlobalDictMarshal() - { - return m_pyGlobalDictString; - }; - - void - SetPyGlobalDictMarshal( char* pyGlobalDictString, int length ) - { - if (m_pyGlobalDictString && m_pyGlobalDictString != pyGlobalDictString) - free(m_pyGlobalDictString); - - m_pyGlobalDictString = pyGlobalDictString; - m_pyGlobalDictString_Length = length; - }; - - int - GetPyGlobalDictMarshalLength() - { - return m_pyGlobalDictString_Length; - }; - - protected: bool handleWheel(GHOST_IEvent* event); bool handleButton(GHOST_IEvent* event, bool isDown); diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp index 8fd23318df1..01774a68cc4 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp @@ -301,8 +301,6 @@ int main(int argc, char** argv) GHOST_TUns32 fullScreenHeight= 0; int fullScreenBpp = 32; int fullScreenFrequency = 60; - char* pyGlobalDictString = NULL; /* store python dict data between blend file loading */ - int pyGlobalDictString_Length = 0; GHOST_TEmbedderWindowID parentWindow = 0; @@ -658,10 +656,6 @@ int main(int argc, char** argv) titlename = maggie->name; - // Set the GameLogic.globalDict from marshal'd data, so we can load new blend files - // abd keep data in GameLogic.globalDict - app.SetPyGlobalDictMarshal(pyGlobalDictString, pyGlobalDictString_Length); - // Check whether the game should be displayed full-screen if ((!fullScreenParFound) && (!windowParFound)) { @@ -790,12 +784,7 @@ int main(int argc, char** argv) } } app.StopGameEngine(); - - // GameLogic.globalDict has been converted into a buffer - // store in pyGlobalDictString so we can restore after python has stopped and started. - pyGlobalDictString = app.GetPyGlobalDictMarshal(); - pyGlobalDictString_Length = app.GetPyGlobalDictMarshalLength(); - + BLO_blendfiledata_free(bfd); } } while (exitcode == KX_EXIT_REQUEST_RESTART_GAME || exitcode == KX_EXIT_REQUEST_START_OTHER_GAME); @@ -814,11 +803,6 @@ int main(int argc, char** argv) free_nodesystem(); - if (pyGlobalDictString) { - free(pyGlobalDictString); - pyGlobalDictString = NULL; - } - return error ? -1 : 0; } -- cgit v1.2.3