Fix occasional crash

This commit is contained in:
tobspr 2020-06-04 22:43:33 +02:00
parent 458aeae4c8
commit a222f59c15
1 changed files with 21 additions and 7 deletions

View File

@ -256,11 +256,15 @@ export class Application {
onAppRenderableStateChanged(renderable) { onAppRenderableStateChanged(renderable) {
logger.log("Application renderable:", renderable); logger.log("Application renderable:", renderable);
window.focus(); window.focus();
const currentState = this.stateMgr.getCurrentState();
if (!renderable) { if (!renderable) {
this.stateMgr.getCurrentState().onAppPause(); if (currentState) {
currentState.onAppPause();
}
} else { } else {
// Got resume if (currentState) {
this.stateMgr.getCurrentState().onAppResume(); currentState.onAppResume();
}
this.checkResize(); this.checkResize();
} }
@ -274,7 +278,10 @@ export class Application {
if (!this.unloaded) { if (!this.unloaded) {
logSection("UNLOAD HANDLER", "#f77"); logSection("UNLOAD HANDLER", "#f77");
this.unloaded = true; this.unloaded = true;
this.stateMgr.getCurrentState().onBeforeExit(); const currentState = this.stateMgr.getCurrentState();
if (currentState) {
currentState.onBeforeExit();
}
this.deinitialize(); this.deinitialize();
} }
} }
@ -284,8 +291,9 @@ export class Application {
*/ */
onBeforeUnload(event) { onBeforeUnload(event) {
logSection("BEFORE UNLOAD HANDLER", "#f77"); logSection("BEFORE UNLOAD HANDLER", "#f77");
const currentState = this.stateMgr.getCurrentState();
if (!G_IS_DEV && this.stateMgr.getCurrentState().getHasUnloadConfirmation()) { if (!G_IS_DEV && currentState && currentState.getHasUnloadConfirmation()) {
if (!G_IS_STANDALONE) { if (!G_IS_STANDALONE) {
// Need to show a "Are you sure you want to exit" // Need to show a "Are you sure you want to exit"
event.preventDefault(); event.preventDefault();
@ -335,7 +343,10 @@ export class Application {
return; return;
} }
this.stateMgr.getCurrentState().onBackgroundTick(dt); const currentState = this.stateMgr.getCurrentState();
if (currentState) {
currentState.onBackgroundTick(dt);
}
} }
/** /**
@ -355,7 +366,10 @@ export class Application {
this.lastResizeCheck = time; this.lastResizeCheck = time;
} }
this.stateMgr.getCurrentState().onRender(dt); const currentState = this.stateMgr.getCurrentState();
if (currentState) {
currentState.onRender(dt);
}
} }
/** /**