Skip to content

Commit 366017f

Browse files
committed
UPBGE: Fix python segfault on blenderplayer error.
Previously if the blenderplayer file can't be loaded or any other error was raised. Then the globalDict which was allocated before was tryed deleted at the end of the blenderplayer main. But if a error is raised the launcher is not created then python is not initialized and the globalDict variable can't be deleted. To fix this issue the globalDict is set to NULL as default and allocated just after the creation of the launcher to make sure that python was initialized. We do the same by checking at the end of main if globalDict is non NULL before try delete it. This problem is encoutered in blenderplayer only as the embedded player reuse the existing python context of blender.
1 parent 7beccfd commit 366017f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

source/gameengine/GamePlayer/GPG_ghost.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ int main(
861861
GlobalSettings gs;
862862

863863
#ifdef WITH_PYTHON
864-
PyObject *globalDict = PyDict_New();
864+
PyObject *globalDict = NULL;
865865
#endif // WITH_PYTHON
866866

867867
do {
@@ -987,6 +987,9 @@ int main(
987987

988988
LA_PlayerLauncher launcher(system, maggie, scene, &gs, stereomode, argc, argv); /* this argc cant be argc_py_clamped, since python uses it */
989989
#ifdef WITH_PYTHON
990+
if (!globalDict) {
991+
globalDict = PyDict_New();
992+
}
990993
launcher.SetPythonGlobalDict(globalDict);
991994
#endif // WITH_PYTHON
992995

@@ -1084,9 +1087,11 @@ int main(
10841087
} while (exitcode == KX_EXIT_REQUEST_RESTART_GAME || exitcode == KX_EXIT_REQUEST_START_OTHER_GAME);
10851088

10861089
#ifdef WITH_PYTHON
1087-
1088-
PyDict_Clear(globalDict);
1089-
Py_DECREF(globalDict);
1090+
// If the globalDict is to NULL then python is certainly not initialized.
1091+
if (globalDict) {
1092+
PyDict_Clear(globalDict);
1093+
Py_DECREF(globalDict);
1094+
}
10901095
#endif
10911096
}
10921097

0 commit comments

Comments
 (0)