[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32385] trunk/blender/source/gameengine/ Ketsji/KX_PythonInit.cpp: Fixing a memory leak with SCA_PythonKeyboard and SCA_PythonMouse.

Mitchell Stokes mogurijin at gmail.com
Sat Oct 9 03:31:23 CEST 2010


Revision: 32385
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32385
Author:   moguri
Date:     2010-10-09 03:31:20 +0200 (Sat, 09 Oct 2010)

Log Message:
-----------
Fixing a memory leak with SCA_PythonKeyboard and SCA_PythonMouse.

Modified Paths:
--------------
    trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp

Modified: trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp	2010-10-08 22:33:43 UTC (rev 32384)
+++ trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp	2010-10-09 01:31:20 UTC (rev 32385)
@@ -141,6 +141,8 @@
 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 @@
 	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 @@
 
 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 @@
 
 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();





More information about the Bf-blender-cvs mailing list