Revision: 35364
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=35364
Author:   campbellbarton
Date:     2011-03-05 11:08:22 +0000 (Sat, 05 Mar 2011)
Log Message:
-----------
patch [#26366] More detailed Python error reporting for the BGE
from Alex Fraser (z0r)

    Now object name is shown with python error.

Modified Paths:
--------------
    trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp

Modified: trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp  
2011-03-05 10:37:59 UTC (rev 35363)
+++ trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp  
2011-03-05 11:08:22 UTC (rev 35364)
@@ -262,10 +262,7 @@
 
 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 @@
        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 @@
                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 @@
        
        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 @@
        
        /* 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 */
        {

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to