diff options
| author | srdusr <trevorgray@srdusr.com> | 2025-09-30 13:15:59 +0200 |
|---|---|---|
| committer | srdusr <trevorgray@srdusr.com> | 2025-09-30 13:15:59 +0200 |
| commit | 18a1b361a9d6567b87c49e8bbbf0bba9ba51687f (patch) | |
| tree | 4892a7d495e44b31bb51a1e24748dcdbe57629da /web/src/hooks | |
| parent | 8d60c7f93407988ee0232ea90980028f299cb0f3 (diff) | |
| download | typerpunk-18a1b361a9d6567b87c49e8bbbf0bba9ba51687f.tar.gz typerpunk-18a1b361a9d6567b87c49e8bbbf0bba9ba51687f.zip | |
TUI: fixed wpm history/made UI more identical to web/ctrl-backspace behaviour/improved accuracy
Web: improved category selection/fixed endscreen responsiveness inconsistency/mistake tracking/clean game memory after use/improve general UI
Diffstat (limited to 'web/src/hooks')
| -rw-r--r-- | web/src/hooks/useCoreGame.ts | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/web/src/hooks/useCoreGame.ts b/web/src/hooks/useCoreGame.ts index 3aa69ec..7e0b287 100644 --- a/web/src/hooks/useCoreGame.ts +++ b/web/src/hooks/useCoreGame.ts @@ -42,14 +42,8 @@ export function useCoreGame() { }, []); const resetGame = async () => { - if (gameRef.current) { - try { - gameRef.current.free(); - } catch (err) { - console.error('Error freeing old game:', err); - } - } - + // Do NOT free() here to avoid freeing while React components may still reference it. + // Create a fresh instance and replace the ref. try { const game = new Game(); gameRef.current = game; @@ -60,14 +54,15 @@ export function useCoreGame() { }; const cleanupGame = () => { - if (gameRef.current) { + const inst = gameRef.current; + if (inst) { try { - gameRef.current.free(); + inst.free(); } catch (err) { console.error('Error cleaning up game:', err); } - gameRef.current = null; } + gameRef.current = null; }; return { |
