python modules in the game engine could point to builtin modules like GameLogic that was cleared.

I added module clearing before there was checks for invalid python objects, so now its not needed for BGE Builtin types at least.

also made the builtin modules get re-used if they already exist and clear all user modules when the game engine finishes so with Module-Py-Controllers the referenced modules are at least up to date when pressing Pkey.
This commit is contained in:
Campbell Barton
2009-04-29 23:39:27 +00:00
parent 537b080379
commit 1e7df58519
7 changed files with 122 additions and 35 deletions

View File

@@ -272,7 +272,12 @@ PyMethodDef bpy_reload_meth[] = { {"bpy_reload_meth", blender_reload, METH_VARAR
* Its also needed for the BGE Python api so imported scripts are not used between levels
*
* This clears every modules that has a __file__ attribute (is not a builtin)
* and is a filename only (no path). since pythons bultins include a full path even for win32.
*
* Note that clearing external python modules is important for the BGE otherwise
* it wont reload scripts between loading different blend files or while making the game.
* - use 'clear_all' arg in this case.
*
* Since pythons bultins include a full path even for win32.
* even if we remove a python module a reimport will bring it back again.
*/
@@ -284,7 +289,7 @@ PyMethodDef bpy_reload_meth[] = { {"bpy_reload_meth", blender_reload, METH_VARAR
#endif
void bpy_text_clear_modules(void)
void bpy_text_clear_modules(int clear_all)
{
PyObject *modules= PySys_GetObject("modules");
@@ -309,7 +314,7 @@ void bpy_text_clear_modules(void)
while (PyDict_Next(modules, &pos, &key, &value)) {
fname= PyModule_GetFilename(value);
if(fname) {
if ((strstr(fname, SEPSTR))==0) { /* no path ? */
if (clear_all || ((strstr(fname, SEPSTR))==0)) { /* no path ? */
file_extension = strstr(fname, ".py");
if(file_extension && *(file_extension + 3) == '\0') { /* .py extension ? */
/* now we can be fairly sure its a python import from the blendfile */

View File

@@ -37,7 +37,7 @@
PyObject* bpy_text_import( char *name, int *found );
PyObject* bpy_text_reimport( PyObject *module, int *found );
void bpy_text_clear_modules( void ); /* Clear user modules */
void bpy_text_clear_modules( int clear_all ); /* Clear user modules */
extern PyMethodDef bpy_import_meth[];
extern PyMethodDef bpy_reload_meth[];