Crashes on Scene Changes

Hi guys,
I’ve been trying to teach myself Python by making a game in Blender’s game engine and, with the help of this community, it’s been going great up until now. I recently started getting odd crashes when changing levels. If I’m using the embedded player, blender will crash and close without an error message. If I use the standalone player I get a “Blender has stopped working” error, but only the player crashes. The crashes aren’t consistent either, and almost seem to come in waves… but that’s more than likely my sanity leaving.

I accomplish level changes by suspending the current level scene and adding in a “Next Level” overlay scene, prompting the player to press a continue button. Once pressed, the next level’s scene is added, and both the “Next Level” overlay scene and the old level’s scene are ended.

I sent a test executable to two friends, one of which was unable to get past the start menu scene without it crashing. The other tried it on two different computers and told me that on the first (very old) computer the game crashed randomly after around 20 seconds and not due to scene changes, while the on the second computer he was able to play the game fine with almost no crashes.

I’m really stumped with this one and was hoping someone here might be able to lend some insight. I’ve got a sneaking suspicion that it’s got something to do with the way I add and remove scenes, but the fact that the crashes behave differently on different computers makes me scared the problem is more technical. I’ve attached a .zip containing the .blend and four python scripts used.

Test.zip (368 KB)

Try using replace instead of adding scenes as overlays and then ending the current ones. I’ve had Blender crash when ending the current scene before.


g.getCurrentScene().replace("Level2")

Also, I wouldn’t end scenes by their index (scene[0].end()). I would get the scene by name and end it that way.


for i in g.getSceneList():
    if "Overlay" in i.name:
        i.end()

I haven’t gotten a chance to test your blend yet, but you can try that.