Skip to content

Commit

Permalink
UPBGE: Fix global dict freed in blenderplayer after Py_Finalize.
Browse files Browse the repository at this point in the history
Previously the globalDict was tried to be free after the call
to Py_Finalize which caused to rasie a segmentation fault due
to that fact that the python commands aren't valid after calling
Py_Finalize.

To solve this issue the globalDict is freed just before destructing
the launcher which finlize python.
  • Loading branch information
panzergame committed Oct 17, 2016
1 parent 9fb9069 commit 0980316
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions source/gameengine/GamePlayer/GPG_ghost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,8 @@ int main(
PyObject *globalDict = NULL;
#endif // WITH_PYTHON

bool quit = false;

do {
// Read the Blender file
BlendFileData *bfd;
Expand Down Expand Up @@ -1285,21 +1287,28 @@ int main(
exitstring = launcher.GetExitString();
gs = *launcher.GetGlobalSettings();

// Exit the game engine if we are not restarting the game or loading an other file.
quit = (exitcode != KX_EXIT_REQUEST_RESTART_GAME && exitcode != KX_EXIT_REQUEST_START_OTHER_GAME);

/* Delete the globalDict before free the launcher, because the launcher calls
* Py_Finalize() which disallow any python commands after.
*/
if (quit) {
#ifdef WITH_PYTHON
// If the globalDict is to NULL then python is certainly not initialized.
if (globalDict) {
PyDict_Clear(globalDict);
Py_DECREF(globalDict);
}
#endif
}
launcher.ExitEngine();

BLO_blendfiledata_free(bfd);
/* G.main == bfd->main, it gets referenced in free_nodesystem so we can't have a dangling pointer */
G.main = NULL;
}
} while (exitcode == KX_EXIT_REQUEST_RESTART_GAME || exitcode == KX_EXIT_REQUEST_START_OTHER_GAME);

#ifdef WITH_PYTHON
// If the globalDict is to NULL then python is certainly not initialized.
if (globalDict) {
PyDict_Clear(globalDict);
Py_DECREF(globalDict);
}
#endif
} while (!quit);
}

// Seg Fault; icon.c gIcons == 0
Expand Down

0 comments on commit 0980316

Please sign in to comment.