diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 1e490a4cf986..00bb71bf31aa 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -1452,6 +1452,7 @@ PyMODINIT_FUNC initGameLogicPythonBinding() PyList_SET_ITEM(joylist, i, Py_None); } PyDict_SetItemString(d, "joysticks", joylist); + Py_DECREF(joylist); ErrorObject = PyUnicode_FromString("GameLogic.error"); PyDict_SetItemString(d, "error", ErrorObject); @@ -2057,7 +2058,9 @@ void initGamePlayerPythonScripting(Main *maggie, int argc, char** argv) } #endif - PyDict_SetItemString(PyImport_GetModuleDict(), "bge", initBGE()); + PyObject *mod = initBGE(); + PyDict_SetItemString(PyImport_GetModuleDict(), "bge", mod); + Py_DECREF(mod); first_time = false; @@ -2109,7 +2112,9 @@ void initGamePythonScripting(Main *maggie) } #endif - PyDict_SetItemString(PyImport_GetModuleDict(), "bge", initBGE()); + PyObject *mod = initBGE(); + PyDict_SetItemString(PyImport_GetModuleDict(), "bge", mod); + Py_DECREF(mod); EXP_PyObjectPlus::NullDeprecationWarning(); } @@ -2137,8 +2142,7 @@ void exitGamePythonScripting() /* similar to the above functions except it sets up the namespace * and other more general things */ -void setupGamePython(KX_KetsjiEngine* ketsjiengine, Main *blenderdata, - PyObject *pyGlobalDict, PyObject **gameLogic, int argc, char** argv) +void setupGamePython(KX_KetsjiEngine* ketsjiengine, Main *blenderdata, PyObject *pyGlobalDict, int argc, char** argv) { PyObject *modules; @@ -2149,10 +2153,11 @@ void setupGamePython(KX_KetsjiEngine* ketsjiengine, Main *blenderdata, modules = PyImport_GetModuleDict(); - *gameLogic = PyDict_GetItemString(modules, "GameLogic"); + PyObject *gameLogic = PyDict_GetItemString(modules, "GameLogic"); /* is set in initGameLogicPythonBinding so only set here if we want it to persist between scenes */ if (pyGlobalDict) - PyDict_SetItemString(PyModule_GetDict(*gameLogic), "globalDict", pyGlobalDict); // Same as importing the module.z + PyDict_SetItemString(PyModule_GetDict(gameLogic), "globalDict", pyGlobalDict); // Same as importing the module.z + Py_DECREF(gameLogic); } void createPythonConsole() diff --git a/source/gameengine/Ketsji/KX_PythonInit.h b/source/gameengine/Ketsji/KX_PythonInit.h index c3891ef01569..e7e6395ff31d 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.h +++ b/source/gameengine/Ketsji/KX_PythonInit.h @@ -54,8 +54,7 @@ void appendPythonPath(const std::string& path); void exitGamePlayerPythonScripting(); void exitGamePythonScripting(); -void setupGamePython(KX_KetsjiEngine *ketsjiengine, Main *blenderdata, - PyObject *pyGlobalDict, PyObject **gameLogic, int argc, char **argv); +void setupGamePython(KX_KetsjiEngine *ketsjiengine, Main *blenderdata, PyObject *pyGlobalDict, int argc, char **argv); std::string pathGamePythonConfig(); void saveGamePythonConfig(); void loadGamePythonConfig(); diff --git a/source/gameengine/Launcher/LA_Launcher.cpp b/source/gameengine/Launcher/LA_Launcher.cpp index 99e6d366c527..fc45867e7d00 100644 --- a/source/gameengine/Launcher/LA_Launcher.cpp +++ b/source/gameengine/Launcher/LA_Launcher.cpp @@ -96,7 +96,6 @@ LA_Launcher::LA_Launcher(GHOST_ISystem *system, Main *maggie, Scene *scene, Glob m_converter(nullptr), #ifdef WITH_PYTHON m_globalDict(nullptr), - m_gameLogic(nullptr), #endif // WITH_PYTHON m_samples(samples), m_stereoMode(stereoMode), @@ -276,7 +275,7 @@ void LA_Launcher::InitEngine() #ifdef WITH_PYTHON KX_SetMainPath(std::string(m_maggie->name)); // Some python things. - setupGamePython(m_ketsjiEngine, m_maggie, m_globalDict, &m_gameLogic, m_argc, m_argv); + setupGamePython(m_ketsjiEngine, m_maggie, m_globalDict, m_argc, m_argv); #endif // WITH_PYTHON // Create a scene converter, create and convert the stratingscene. @@ -325,19 +324,6 @@ void LA_Launcher::ExitEngine() DEV_Joystick::Close(); m_ketsjiEngine->StopEngine(); -#ifdef WITH_PYTHON - - /* Clears the dictionary by hand: - * This prevents, extra references to global variables - * inside the GameLogic dictionary when the python interpreter is finalized. - * which allows the scene to safely delete them :) - * see: (space.c)->start_game - */ - - PyDict_Clear(PyModule_GetDict(m_gameLogic)); - -#endif // WITH_PYTHON - // Do we will stop ? if ((m_exitRequested != KX_ExitRequest::RESTART_GAME) && (m_exitRequested != KX_ExitRequest::START_OTHER_GAME)) { // Then set the cursor back to normal here to avoid set the cursor visible between two game load. diff --git a/source/gameengine/Launcher/LA_Launcher.h b/source/gameengine/Launcher/LA_Launcher.h index a8b337f37e21..cfd094a3cd59 100644 --- a/source/gameengine/Launcher/LA_Launcher.h +++ b/source/gameengine/Launcher/LA_Launcher.h @@ -82,7 +82,6 @@ class LA_Launcher #ifdef WITH_PYTHON PyObject *m_globalDict; - PyObject *m_gameLogic; #endif // WITH_PYTHON /// The number of render samples. diff --git a/source/gameengine/VideoTexture/blendVideoTex.cpp b/source/gameengine/VideoTexture/blendVideoTex.cpp index 2ca134340687..7180544f42cf 100644 --- a/source/gameengine/VideoTexture/blendVideoTex.cpp +++ b/source/gameengine/VideoTexture/blendVideoTex.cpp @@ -214,6 +214,7 @@ PyMODINIT_FUNC initVideoTexturePythonBinding(void) pyImageTypes.reg(m); pyFilterTypes.reg(m); + Py_INCREF(&Texture::Type); PyModule_AddObject(m, "Texture", (PyObject *)&Texture::Type); #ifdef WITH_GAMEENGINE_DECKLINK Py_INCREF(&DeckLinkType);