diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-03-05 14:08:22 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-03-05 14:08:22 +0300 |
commit | 3a590b4ec7a2c4f99e104bd2851bf2da46817173 (patch) | |
tree | 523bb127185e39e6ecf23bb7426d111c09bac10a /source/gameengine/GameLogic | |
parent | 2610881e9c6d15c403c3b923650569fb87258264 (diff) |
patch [#26366] More detailed Python error reporting for the BGE
from Alex Fraser (z0r)
Now object name is shown with python error.
Diffstat (limited to 'source/gameengine/GameLogic')
-rw-r--r-- | source/gameengine/GameLogic/SCA_PythonController.cpp | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp index 4e021141f22..be138db620e 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.cpp +++ b/source/gameengine/GameLogic/SCA_PythonController.cpp @@ -262,10 +262,7 @@ PyAttributeDef SCA_PythonController::Attributes[] = { void SCA_PythonController::ErrorPrint(const char *error_msg) { - // didn't compile, so instead of compile, complain - // something is wrong, tell the user what went wrong - printf("%s - controller \"%s\":\n", error_msg, GetName().Ptr()); - //PyRun_SimpleString(m_scriptText.Ptr()); + printf("%s - object '%s', controller '%s':\n", error_msg, GetParent()->GetName().Ptr(), GetName().Ptr()); PyErr_Print(); /* Added in 2.48a, the last_traceback can reference Objects for example, increasing @@ -314,7 +311,7 @@ bool SCA_PythonController::Import() function_string= strrchr(mod_path, '.'); if(function_string == NULL) { - printf("Python module name formatting error \"%s\":\n\texpected \"SomeModule.Func\", got \"%s\"\n", GetName().Ptr(), m_scriptText.Ptr()); + printf("Python module name formatting error in object '%s', controller '%s':\n\texpected 'SomeModule.Func', got '%s'\n", GetParent()->GetName().Ptr(), GetName().Ptr(), m_scriptText.Ptr()); return false; } @@ -347,13 +344,14 @@ bool SCA_PythonController::Import() if(PyErr_Occurred()) ErrorPrint("Python controller found the module but could not access the function"); else - printf("Python module error \"%s\":\n \"%s\" module found but function missing\n", GetName().Ptr(), m_scriptText.Ptr()); + printf("Python module error in object '%s', controller '%s':\n '%s' module found but function missing\n", GetParent()->GetName().Ptr(), GetName().Ptr(), m_scriptText.Ptr()); return false; } if(!PyCallable_Check(m_function)) { Py_DECREF(m_function); - printf("Python module function error \"%s\":\n \"%s\" not callable\n", GetName().Ptr(), m_scriptText.Ptr()); + m_function = NULL; + printf("Python module function error in object '%s', controller '%s':\n '%s' not callable\n", GetParent()->GetName().Ptr(), GetName().Ptr(), m_scriptText.Ptr()); return false; } @@ -371,7 +369,8 @@ bool SCA_PythonController::Import() if(m_function_argc > 1) { Py_DECREF(m_function); - printf("Python module function has \"%s\":\n \"%s\" takes %d args, should be zero or 1 controller arg\n", GetName().Ptr(), m_scriptText.Ptr(), m_function_argc); + m_function = NULL; + printf("Python module function in object '%s', controller '%s':\n '%s' takes %d args, should be zero or 1 controller arg\n", GetParent()->GetName().Ptr(), GetName().Ptr(), m_scriptText.Ptr(), m_function_argc); return false; } @@ -451,22 +450,9 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr) /* Free the return value and print the error */ if (resultobj) - { Py_DECREF(resultobj); - } else - { - // 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 already dealocated the pointer */ - PySys_SetObject( (char *)"last_traceback", NULL); - PyErr_Clear(); /* just to be sure */ - } + ErrorPrint("Python script error"); if(excdict) /* Only for SCA_PYEXEC_SCRIPT types */ { |