Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions GDJS/Runtime/InGameEditor/InGameEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,17 @@ namespace gdjs {
};

let hasWindowFocus = true;
// References for cleanup
const _onWindowFocus = () => {
hasWindowFocus = true;
};
const _onWindowBlur = () => {
hasWindowFocus = false;
};

if (typeof window !== 'undefined') {
window.addEventListener('focus', () => {
hasWindowFocus = true;
});
window.addEventListener('blur', () => {
hasWindowFocus = false;
});
window.addEventListener('focus', _onWindowFocus);
window.addEventListener('blur', _onWindowBlur);
}

function isDefined<T>(value: T | null | undefined): value is NonNullable<T> {
Expand Down Expand Up @@ -962,6 +966,10 @@ namespace gdjs {
this._unregisterContextLostListener();
this._unregisterContextLostListener = null;
}
if (typeof window !== 'undefined') {
window.removeEventListener('focus', _onWindowFocus);
window.removeEventListener('blur', _onWindowBlur);
}
}

private _applyInGameEditorSettings() {
Expand Down
2 changes: 2 additions & 0 deletions GDJS/Runtime/debugger-client/abstract-debugger-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ namespace gdjs {
}
}

abstract dispose(): void;

/**
* Should be re-implemented by derived class to send a stringified message object
* to the debugger server.
Expand Down
2 changes: 2 additions & 0 deletions GDJS/Runtime/debugger-client/minimal-debugger-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace gdjs {
super(runtimeGame);
}

dispose(): void {}

protected _sendMessage(message: string) {}
}

Expand Down
7 changes: 7 additions & 0 deletions GDJS/Runtime/debugger-client/websocket-debugger-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ namespace gdjs {
}

private hasLoggedError: boolean = false;

dispose(): void {
if (this._ws) {
this._ws.close();
}
}

protected _sendMessage(message: string) {
if (!this._ws) {
// The error can be logged only once, since logger.warn will call this function again,
Expand Down
13 changes: 9 additions & 4 deletions GDJS/Runtime/debugger-client/window-message-debugger-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ namespace gdjs {
*/
export class WindowMessageDebuggerClient extends gdjs.AbstractDebuggerClient {
_opener: Window | null = null;
private _onWindowMessage = (event: MessageEvent) => {
const data = event.data;
this.handleCommand(data);
};

constructor(runtimeGame: RuntimeGame) {
super(runtimeGame);
Expand All @@ -24,10 +28,11 @@ namespace gdjs {
return;
}

window.addEventListener('message', (event) => {
const data = event.data;
this.handleCommand(data);
});
window.addEventListener('message', this._onWindowMessage);
}

dispose() {
window.removeEventListener('message', this._onWindowMessage);
}

protected _sendMessage(message: string) {
Expand Down
3 changes: 3 additions & 0 deletions GDJS/Runtime/runtimegame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,9 @@ namespace gdjs {
if (this._inGameEditor) {
this._inGameEditor.dispose();
}
if (this._debuggerClient) {
this._debuggerClient.dispose();
}
this._renderer.stopGameLoop();
this._sceneStack.dispose();
this._renderer.dispose(removeCanvas);
Expand Down