Skip to content

Commit d98db41

Browse files
committed
dispose world: sanity check for currentscene!=null
1 parent c3fc8d7 commit d98db41

File tree

1 file changed

+16
-11
lines changed
  • blade-engine/src/com/bladecoder/engine/model

1 file changed

+16
-11
lines changed

blade-engine/src/com/bladecoder/engine/model/World.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -420,18 +420,21 @@ public void dispose() {
420420

421421
textManager.reset();
422422
timers.clear();
423-
currentScene.stopMusic();
423+
424424
currentDialog = null;
425425

426426
transition.reset();
427427

428428
// Clear all pending callbacks
429429
ActionCallbackQueue.clear();
430-
430+
431431
// ONLY dispose currentscene because other scenes are already
432432
// disposed
433-
currentScene.dispose();
434-
currentScene = null;
433+
if (currentScene != null) {
434+
currentScene.stopMusic();
435+
currentScene.dispose();
436+
currentScene = null;
437+
}
435438

436439
if (cachedScene != null) {
437440
cachedScene.dispose();
@@ -514,7 +517,8 @@ public void newGame() throws Exception {
514517
/**
515518
* Try to load the save game if exists. In other case, load the game from
516519
* XML.
517-
* @throws Exception
520+
*
521+
* @throws Exception
518522
*
519523
* @throws IOException
520524
* @throws SAXException
@@ -538,7 +542,8 @@ public void load() throws Exception {
538542
/**
539543
* Load the world description. First try to load 'world.json'. If doesn't
540544
* exists try 'world.xml'.
541-
* @throws IOException
545+
*
546+
* @throws IOException
542547
*/
543548
public void loadWorldDesc() throws IOException {
544549
if (EngineAssetManager.getInstance().getModelFile(EngineAssetManager.WORLD_FILENAME_JSON).exists()) {
@@ -616,7 +621,7 @@ public void loadChapter(String chapterName) throws IOException {
616621

617622
if (chapterName == null)
618623
chapterName = initChapter;
619-
624+
620625
currentChapter = initChapter;
621626

622627
if (EngineAssetManager.getInstance().getModelFile(chapterName + EngineAssetManager.CHAPTER_EXT).exists()) {
@@ -812,7 +817,7 @@ public void write(Json json) {
812817
json.writeValue("currentDialog", currentDialog.getId());
813818
}
814819

815-
if(transition != null)
820+
if (transition != null)
816821
json.writeValue("transition", transition);
817822

818823
json.writeValue("chapter", currentChapter);
@@ -836,18 +841,18 @@ public void read(Json json, JsonValue jsonData) {
836841
for (Scene s : scenes.values()) {
837842
s.resetCamera(width, height);
838843
}
839-
844+
840845
setCurrentScene(initScene);
841846
} else {
842847
currentChapter = json.readValue("chapter", String.class, jsonData);
843-
848+
844849
try {
845850
loadChapter(currentChapter);
846851
} catch (IOException e1) {
847852
EngineLogger.error("Error Loading Chapter");
848853
return;
849854
}
850-
855+
851856
// restore the state after loading the model
852857
SerializationHelper.getInstance().setMode(Mode.STATE);
853858

0 commit comments

Comments
 (0)