diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-08-05 07:25:45 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-08-05 07:25:45 +0400 |
commit | a0cece42c646df39c858223b0361b7dfe0d44dd8 (patch) | |
tree | 78c8990de78ecf4ebc06b26a953ecf0bb83d91b0 /source/gameengine | |
parent | db5a5c131cc9d379c74c1b9afd116d61af87feb7 (diff) |
bugfix [#23148] "ImportError: __import__ not found" on changing Render FPS
The BGE was getting the namespace dict directly from __main__ which conflicts
with my recent fix to get the pickle module working which to overwrote the __main__ module on script execution.
Simple fix is to have the BGE and Blender use the same method of getting namespaces.
Renamed CreateGlobalDictionary() to bpy_namespace_dict_new() and moved into bpy_internal_import.c
pickle still wont work in the BGE since we make a copy of __main__ namespace but for speed would rather not have to replace the __main__ module many times per second.
Diffstat (limited to 'source/gameengine')
-rw-r--r-- | source/gameengine/Converter/KX_ConvertControllers.cpp | 8 | ||||
-rw-r--r-- | source/gameengine/GameLogic/SCA_PythonController.cpp | 12 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_KetsjiEngine.h | 1 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonInit.cpp | 10 |
4 files changed, 18 insertions, 13 deletions
diff --git a/source/gameengine/Converter/KX_ConvertControllers.cpp b/source/gameengine/Converter/KX_ConvertControllers.cpp index 858db6d76a1..a6b62ecb7b0 100644 --- a/source/gameengine/Converter/KX_ConvertControllers.cpp +++ b/source/gameengine/Converter/KX_ConvertControllers.cpp @@ -176,11 +176,11 @@ void BL_ConvertControllers( /* let the controller print any warnings here when importing */ pyctrl->SetScriptText(STR_String(pycont->module)); pyctrl->SetScriptName(pycont->module); /* will be something like module.func so using it as the name is OK */ - } - if(pycont->flag & CONT_PY_DEBUG) { - printf("\nDebuging \"%s\", module for object %s\n\texpect worse performance.\n", pycont->module, blenderobject->id.name+2); - pyctrl->SetDebug(true); + if(pycont->flag & CONT_PY_DEBUG) { + printf("\nDebuging \"%s\", module for object %s\n\texpect worse performance.\n", pycont->module, blenderobject->id.name+2); + pyctrl->SetDebug(true); + } } #endif // DISABLE_PYTHON diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp index bcc61b533c3..48fdcb3eb44 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.cpp +++ b/source/gameengine/GameLogic/SCA_PythonController.cpp @@ -305,7 +305,7 @@ bool SCA_PythonController::Import() char *function_string; 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()); return false; @@ -316,11 +316,17 @@ bool SCA_PythonController::Import() // Import the module and print an error if it's not found PyObject *mod = PyImport_ImportModule(mod_path); - if(mod && m_debug) + + if (mod == NULL) { + ErrorPrint("Python module can't be imported"); + return false; + } + + if(m_debug) mod = PyImport_ReloadModule(mod); if (mod == NULL) { - ErrorPrint("Python module not found"); + ErrorPrint("Python module can't be reloaded"); return false; } diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.h b/source/gameengine/Ketsji/KX_KetsjiEngine.h index 0a461a8b63e..f52ec8192cc 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.h +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.h @@ -71,6 +71,7 @@ private: class KX_ISceneConverter* m_sceneconverter; class NG_NetworkDeviceInterface* m_networkdevice; #ifndef DISABLE_PYTHON + /* borrowed from sys.modules["__main__"], dont manage ref's */ PyObject* m_pythondictionary; #endif class SCA_IInputDevice* m_keyboarddevice; diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 7327b9c08ff..2e490c24217 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -1912,9 +1912,8 @@ PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecur first_time = false; PyObjectPlus::ClearDeprecationWarning(); - - PyObject* moduleobj = PyImport_AddModule("__main__"); - return PyModule_GetDict(moduleobj); + + return bpy_namespace_dict_new(NULL); } void exitGamePlayerPythonScripting() @@ -1949,9 +1948,8 @@ PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLev initPySysObjects(maggie); PyObjectPlus::NullDeprecationWarning(); - - PyObject* moduleobj = PyImport_AddModule("__main__"); - return PyModule_GetDict(moduleobj); + + return bpy_namespace_dict_new(NULL); } void exitGamePythonScripting() |