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.
This commit is contained in:
@@ -350,3 +350,26 @@ void bpy_text_clear_modules(int clear_all)
|
||||
Py_DECREF(list); /* removes all references from append */
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Description: This function creates a new Python dictionary object.
|
||||
* note: dict is owned by sys.modules["__main__"] module, reference is borrowed
|
||||
* note: important we use the dict from __main__, this is what python expects
|
||||
for 'pickle' to work as well as strings like this...
|
||||
>> foo = 10
|
||||
>> print(__import__("__main__").foo)
|
||||
*****************************************************************************/
|
||||
PyObject *bpy_namespace_dict_new(const char *filename)
|
||||
{
|
||||
PyInterpreterState *interp= PyThreadState_GET()->interp;
|
||||
PyObject *mod_main= PyModule_New("__main__");
|
||||
PyDict_SetItemString(interp->modules, "__main__", mod_main);
|
||||
Py_DECREF(mod_main); /* sys.modules owns now */
|
||||
PyModule_AddStringConstant(mod_main, "__name__", "__main__");
|
||||
if(filename)
|
||||
PyModule_AddStringConstant(mod_main, "__file__", filename); /* __file__ only for nice UI'ness */
|
||||
PyModule_AddObject(mod_main, "__builtins__", interp->builtins);
|
||||
Py_INCREF(interp->builtins); /* AddObject steals a reference */
|
||||
return PyModule_GetDict(mod_main);
|
||||
}
|
||||
|
||||
@@ -60,5 +60,7 @@ extern PyMethodDef bpy_reload_meth[];
|
||||
struct Main *bpy_import_main_get(void);
|
||||
void bpy_import_main_set(struct Main *maggie);
|
||||
|
||||
/* name namespace function for bpy & bge */
|
||||
PyObject *bpy_namespace_dict_new(const char *filename);
|
||||
|
||||
#endif /* EXPP_bpy_import_h */
|
||||
|
||||
Reference in New Issue
Block a user