Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-05-29 13:22:24 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-05-29 13:22:24 +0400
commitedcb9f88635a130dbf342ce5203b5357e306577c (patch)
tree1078bca08e2bbbfa072a3379b2c3420d0062fa31 /source/gameengine/GameLogic
parent39177018af16b208e41714d454a44c58a2eea0b7 (diff)
workaround for strange python problem in the BGE and BPy API where printing warnings mistook the blender binary for a script - argv[0], Binary lines were printed into the console sometimes causing console beeps and corrupting future console output.
Internal texts file on disk is not used it seems python warnings dont support this (even though exceptions do). The most common cause of this is passing a float as an argument to a method that took an int. get around this by setting __file__ in the namespace to the script name before executing the script, the file lines are not found but at least the output is not weird and confusing. Added read only 'mode' attribute to the python controller so there is a way to tell if its executing a module or a script. Updated docs to better explain execution methods.
Diffstat (limited to 'source/gameengine/GameLogic')
-rw-r--r--source/gameengine/GameLogic/SCA_PythonController.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp
index 52f6bece132..80e4f54c9c5 100644
--- a/source/gameengine/GameLogic/SCA_PythonController.cpp
+++ b/source/gameengine/GameLogic/SCA_PythonController.cpp
@@ -147,6 +147,11 @@ void SCA_PythonController::SetDictionary(PyObject* pythondictionary)
Py_DECREF(m_pythondictionary);
}
m_pythondictionary = PyDict_Copy(pythondictionary); /* new reference */
+
+ /* Without __file__ set the sys.argv[0] is used for the filename
+ * which ends up with lines from the blender binary being printed in the console */
+ PyDict_SetItemString(m_pythondictionary, "__file__", PyString_FromString(m_scriptName.Ptr()));
+
}
int SCA_PythonController::IsTriggered(class SCA_ISensor* sensor)
@@ -266,6 +271,7 @@ PyMethodDef SCA_PythonController::Methods[] = {
PyAttributeDef SCA_PythonController::Attributes[] = {
KX_PYATTRIBUTE_RW_FUNCTION("script", SCA_PythonController, pyattr_get_script, pyattr_set_script),
+ KX_PYATTRIBUTE_INT_RO("mode", SCA_PythonController, m_mode),
{ NULL } //Sentinel
};