fix for [#17878] Scripts operating on blender objects don't clear memory after a...
[blender.git] / source / gameengine / GameLogic / SCA_PythonController.cpp
index 4cb9bc8fe530d025c8fb4e7d4c702b8a80822536..1bbb93e0acc9c107b563ab43fcdc4f795a4e84ae 100644 (file)
@@ -262,6 +262,13 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr)
                        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 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr)
                // 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());
        }