[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17163] trunk/blender/source: fix for [ #17878] Scripts operating on blender objects don' t clear memory after a crash
Campbell Barton
ideasman42 at gmail.com
Wed Oct 22 05:10:04 CEST 2008
Revision: 17163
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17163
Author: campbellbarton
Date: 2008-10-22 05:10:00 +0200 (Wed, 22 Oct 2008)
Log Message:
-----------
fix for [#17878] Scripts operating on blender objects don't clear memory after a crash
This is an interesting bug since it is likely the cause of many other suspicious python crashes in blender.
sys.last_traceback would store references to PyObjects at the point of the crash.
it would only free these when sys.last_traceback was set again or on exit.
This caused many crashes in the BGE while testing since python would end up freeing invalid game objects -
When running scripts with errors, Blender would crash every 2-5 runs - in my test just now it crashed after 4 trys.
It could also segfault blender, when (for eg) you run a script that has objects referenced. then load a new file and run another script that raises an error.
In this case all the invalid Blender-Object's user counts would be decremented, even though none of the pointers were still valid.
Modified Paths:
--------------
trunk/blender/source/blender/python/BPY_interface.c
trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp
Modified: trunk/blender/source/blender/python/BPY_interface.c
===================================================================
--- trunk/blender/source/blender/python/BPY_interface.c 2008-10-22 02:59:33 UTC (rev 17162)
+++ trunk/blender/source/blender/python/BPY_interface.c 2008-10-22 03:10:00 UTC (rev 17163)
@@ -616,7 +616,12 @@
}
Py_DECREF( tb );
}
-
+
+ /* Added in 2.48a, the last_traceback can reference Objects for example, increasing
+ * their user count. Not to mention holding references to wrapped data.
+ * This is especially bad when the PyObject for the wrapped data is free'd, after blender
+ * has alredy dealocated the pointer */
+ PySys_SetObject( "last_traceback", Py_None);
return;
}
@@ -2727,6 +2732,8 @@
* Description: This function executes the python script passed by text.
* The Python dictionary containing global variables needs to
* be passed in globaldict.
+* NOTE: Make sure BPY_Err_Handle() runs if this returns NULL
+* otherwise pointers can be left in sys.last_traceback that become invalid.
*****************************************************************************/
static PyObject *RunPython( Text * text, PyObject * globaldict )
{
Modified: trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp 2008-10-22 02:59:33 UTC (rev 17162)
+++ trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp 2008-10-22 03:10:00 UTC (rev 17163)
@@ -262,6 +262,13 @@
printf("Python compile error from controller \"%s\": \n", GetName().Ptr());
//PyRun_SimpleString(m_scriptText.Ptr());
PyErr_Print();
+
+ /* Added in 2.48a, the last_traceback can reference Objects for example, increasing
+ * their user count. Not to mention holding references to wrapped data.
+ * This is especially bad when the PyObject for the wrapped data is free'd, after blender
+ * has alredy dealocated the pointer */
+ PySys_SetObject( "last_traceback", Py_None);
+
return;
}
m_bModified=false;
@@ -298,6 +305,13 @@
// something is wrong, tell the user what went wrong
printf("Python script error from controller \"%s\": \n", GetName().Ptr());
PyErr_Print();
+
+ /* Added in 2.48a, the last_traceback can reference Objects for example, increasing
+ * their user count. Not to mention holding references to wrapped data.
+ * This is especially bad when the PyObject for the wrapped data is free'd, after blender
+ * has alredy dealocated the pointer */
+ PySys_SetObject( "last_traceback", Py_None);
+
//PyRun_SimpleString(m_scriptText.Ptr());
}
More information about the Bf-blender-cvs
mailing list