From 69c6bd604c36e06d704948bce1eb32134ac8971f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 22 Oct 2008 07:09:15 +0000 Subject: [PATCH] make sure BPY_Err_Handle clears python errors, even if the exception cant be printed. Added PyErr_Clear() incase there are other references to exception data (sys.exc_info() from python) --- source/blender/python/BPY_interface.c | 23 +++++++++++++------ .../GameLogic/SCA_PythonController.cpp | 2 ++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c index dfcf6aa35a5..1c8b606ace3 100644 --- a/source/blender/python/BPY_interface.c +++ b/source/blender/python/BPY_interface.c @@ -532,6 +532,16 @@ static PyObject *traceback_getFilename( PyObject * tb ) else return PyString_FromString("unknown"); } +static void BPY_Err_Clear(void) +{ + /* 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); + + PyErr_Clear(); +} /**************************************************************************** * Description: Blender Python error handler. This catches the error and * stores filename and line number in a global @@ -542,6 +552,7 @@ static void BPY_Err_Handle( char *script_name ) if( !script_name ) { printf( "Error: script has NULL name\n" ); + BPY_Err_Clear(); return; } @@ -568,8 +579,9 @@ static void BPY_Err_Handle( char *script_name ) } else { g_script_error.lineno = -1; } - /* this avoids an abort in Python 2.3's garbage collecting: */ - PyErr_Clear( ); + /* this avoids an abort in Python 2.3's garbage collecting: + PyErr_Clear() */ + BPY_Err_Clear(); /* Calls PyErr_Clear as well */ return; } else { PyErr_NormalizeException( &exception, &err, &tb ); @@ -579,6 +591,7 @@ static void BPY_Err_Handle( char *script_name ) if( !tb ) { printf( "\nCan't get traceback\n" ); + BPY_Err_Clear(); /* incase there is still some data hanging about */ return; } @@ -617,11 +630,7 @@ static void BPY_Err_Handle( char *script_name ) 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); + BPY_Err_Clear(); return; } diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp index 1bbb93e0acc..c354ab39747 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.cpp +++ b/source/gameengine/GameLogic/SCA_PythonController.cpp @@ -268,6 +268,7 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr) * 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); + PyErr_Clear(); /* just to be sure */ return; } @@ -311,6 +312,7 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr) * 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); + PyErr_Clear(); /* just to be sure */ //PyRun_SimpleString(m_scriptText.Ptr()); }