From ec155dcb84ec403d83d306f55ece8b704d648f09 Mon Sep 17 00:00:00 2001 From: Evan Date: Tue, 3 Dec 2024 20:04:00 -0800 Subject: [PATCH] fix gameStop undefined error when refreshing page --- TODO.txt | 2 +- src/client/Main.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/TODO.txt b/TODO.txt index d2f65cefb..3a473dceb 100644 --- a/TODO.txt +++ b/TODO.txt @@ -205,7 +205,7 @@ * bugfix: when thread doesn't complete computation, do it in main DONE 12/3/2024 * bugfix: when trade ships captured don't render DONE 12/3/2024 * use mini A* for all pathfinding DONE 12/3/2024 -* bugfix: gameStop not found error +* bugfix: gameStop not found error DONE 12/3/2024 * record and replay games for debugging purposes * bugfix: destroyers can't find path to dst and freeze * log stack traces & display them on screen diff --git a/src/client/Main.ts b/src/client/Main.ts index 6dbe23ccb..064154065 100644 --- a/src/client/Main.ts +++ b/src/client/Main.ts @@ -32,7 +32,9 @@ class Client { const s = this.stopGame window.addEventListener('beforeunload', function (event) { console.log('Browser is closing'); - s() + if (s != null) { + s() + } }); setFavicon() @@ -84,9 +86,7 @@ class Client { } private stopGame() { - if (this.gameStop != null) { - this.gameStop() - } + this?.gameStop?.() } private async handleLeaveLobby(event: CustomEvent) {