Skip to content

Commit

Permalink
UPBGE: Fix deletion of mathutils types in blenderplayer python.
Browse files Browse the repository at this point in the history
The blenderplayer was not calling explicit initialization of mathutils and other
modules and let the user calls the initialization when importing them.
But some of the types defined on these modules can be returned by a python
function without requering to import the module, for example KX_GameObject.worldPosition
return a mathutils.Vector and some scripts don't import mathutils.

To solve this issue the initialization of the modules are explicitly called into
initPlayerPython by looping over bge_internal_modules and calling
PyImport_ImportModuleLevel.

It fix a major issue in blenderplayer scripts.
  • Loading branch information
panzergame committed Jun 13, 2018
1 parent 0b4da63 commit 646ae9d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions source/gameengine/Ketsji/KX_PythonInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2067,13 +2067,12 @@ void initPlayerPython(int argc, char **argv)

bpy_import_init(PyEval_GetBuiltins());

#ifdef WITH_AUDASPACE
/* accessing a SoundActuator's sound results in a crash if aud is not initialized... */
{
PyObject *mod = PyImport_ImportModuleLevel("aud", nullptr, nullptr, nullptr, 0);
/* The modules are imported to call their init functions to ensure the types they own are ready
* as they are used outside of the modules. */
for (unsigned short i = 0; bge_internal_modules[i].name; ++i) {
PyObject *mod = PyImport_ImportModuleLevel(bge_internal_modules[i].name, nullptr, nullptr, nullptr, 0);
Py_DECREF(mod);
}
#endif
}

void exitPlayerPython()
Expand Down

0 comments on commit 646ae9d

Please sign in to comment.