diff options
author | Mitchell Stokes <mogurijin@gmail.com> | 2010-10-09 05:31:20 +0400 |
---|---|---|
committer | Mitchell Stokes <mogurijin@gmail.com> | 2010-10-09 05:31:20 +0400 |
commit | f7fb4e70b3517f6f3e2a0a4823143963fc93f1bf (patch) | |
tree | 96af6a5f52d57790a62cb0b21564e38291a15212 /source/gameengine/Ketsji | |
parent | 9bb10e571b99e4ddbfe11e52bdb385b0433e8b10 (diff) |
Fixing a memory leak with SCA_PythonKeyboard and SCA_PythonMouse.
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonInit.cpp | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index cc44be2654b..88993f20132 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -141,6 +141,8 @@ static char gp_GamePythonPathOrig[FILE_MAXDIR + FILE_MAXFILE] = ""; // not super static KX_Scene* gp_KetsjiScene = NULL; static KX_KetsjiEngine* gp_KetsjiEngine = NULL; static RAS_IRasterizer* gp_Rasterizer = NULL; +static SCA_PythonKeyboard* gp_PythonKeyboard = NULL; +static SCA_PythonMouse* gp_PythonMouse = NULL; void KX_SetActiveScene(class KX_Scene* scene) { @@ -1296,11 +1298,13 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack PyDict_SetItemString(d, "globalDict", item=PyDict_New()); Py_DECREF(item); // Add keyboard and mouse attributes to this module - SCA_PythonKeyboard* pykeyb = new SCA_PythonKeyboard(gp_KetsjiEngine->GetKeyboardDevice()); - PyDict_SetItemString(d, "keyboard", pykeyb->NewProxy(true)); + MT_assert(!gp_PythonKeyboard); + gp_PythonKeyboard = new SCA_PythonKeyboard(gp_KetsjiEngine->GetKeyboardDevice()); + PyDict_SetItemString(d, "keyboard", gp_PythonKeyboard->NewProxy(true)); - SCA_PythonMouse* pymouse = new SCA_PythonMouse(gp_KetsjiEngine->GetMouseDevice(), gp_Canvas); - PyDict_SetItemString(d, "mouse", pymouse->NewProxy(true)); + MT_assert(!gp_PythonMouse); + gp_PythonMouse = new SCA_PythonMouse(gp_KetsjiEngine->GetMouseDevice(), gp_Canvas); + PyDict_SetItemString(d, "mouse", gp_PythonMouse->NewProxy(true)); ErrorObject = PyUnicode_FromString("GameLogic.error"); PyDict_SetItemString(d, "error", ErrorObject); @@ -1926,6 +1930,13 @@ PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecur void exitGamePlayerPythonScripting() { + /* Clean up the Python mouse and keyboard */ + delete gp_PythonKeyboard; + gp_PythonKeyboard = NULL; + + delete gp_PythonMouse; + gp_PythonMouse = NULL; + /* since python restarts we cant let the python backup of the sys.path hang around in a global pointer */ restorePySysObjects(); /* get back the original sys.path and clear the backup */ @@ -1962,6 +1973,13 @@ PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLev void exitGamePythonScripting() { + /* Clean up the Python mouse and keyboard */ + delete gp_PythonKeyboard; + gp_PythonKeyboard = NULL; + + delete gp_PythonMouse; + gp_PythonMouse = NULL; + restorePySysObjects(); /* get back the original sys.path and clear the backup */ bpy_import_main_set(NULL); PyObjectPlus::ClearDeprecationWarning(); |