Fixing a memory leak with SCA_PythonKeyboard and SCA_PythonMouse.
This commit is contained in:
@@ -141,6 +141,8 @@ static char gp_GamePythonPathOrig[FILE_MAXDIR + FILE_MAXFILE] = ""; // not super
|
|||||||
static KX_Scene* gp_KetsjiScene = NULL;
|
static KX_Scene* gp_KetsjiScene = NULL;
|
||||||
static KX_KetsjiEngine* gp_KetsjiEngine = NULL;
|
static KX_KetsjiEngine* gp_KetsjiEngine = NULL;
|
||||||
static RAS_IRasterizer* gp_Rasterizer = 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)
|
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);
|
PyDict_SetItemString(d, "globalDict", item=PyDict_New()); Py_DECREF(item);
|
||||||
|
|
||||||
// Add keyboard and mouse attributes to this module
|
// Add keyboard and mouse attributes to this module
|
||||||
SCA_PythonKeyboard* pykeyb = new SCA_PythonKeyboard(gp_KetsjiEngine->GetKeyboardDevice());
|
MT_assert(!gp_PythonKeyboard);
|
||||||
PyDict_SetItemString(d, "keyboard", pykeyb->NewProxy(true));
|
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);
|
MT_assert(!gp_PythonMouse);
|
||||||
PyDict_SetItemString(d, "mouse", pymouse->NewProxy(true));
|
gp_PythonMouse = new SCA_PythonMouse(gp_KetsjiEngine->GetMouseDevice(), gp_Canvas);
|
||||||
|
PyDict_SetItemString(d, "mouse", gp_PythonMouse->NewProxy(true));
|
||||||
|
|
||||||
ErrorObject = PyUnicode_FromString("GameLogic.error");
|
ErrorObject = PyUnicode_FromString("GameLogic.error");
|
||||||
PyDict_SetItemString(d, "error", ErrorObject);
|
PyDict_SetItemString(d, "error", ErrorObject);
|
||||||
@@ -1926,6 +1930,13 @@ PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecur
|
|||||||
|
|
||||||
void exitGamePlayerPythonScripting()
|
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 */
|
/* 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 */
|
restorePySysObjects(); /* get back the original sys.path and clear the backup */
|
||||||
|
|
||||||
@@ -1962,6 +1973,13 @@ PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLev
|
|||||||
|
|
||||||
void exitGamePythonScripting()
|
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 */
|
restorePySysObjects(); /* get back the original sys.path and clear the backup */
|
||||||
bpy_import_main_set(NULL);
|
bpy_import_main_set(NULL);
|
||||||
PyObjectPlus::ClearDeprecationWarning();
|
PyObjectPlus::ClearDeprecationWarning();
|
||||||
|
|||||||
Reference in New Issue
Block a user