Skip to content

Commit 611fad7

Browse files
committed
web: destroy resources properly on exit
1 parent f331e5e commit 611fad7

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

packages/web/src/lib/components/PixelWorldCanvas.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ $effect(() => {
309309
310310
onDestroy(() => {
311311
stopWorldUpdates();
312+
SimulationService.destroy();
312313
if (app.canvas) {
313314
app.destroy(true);
314315
}

packages/web/src/lib/services/simulation.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ class SimulationService {
4141

4242
return this.wasmSimulation.get_world_state();
4343
};
44+
45+
destroy = () => {
46+
if (!this.wasmSimulation) {
47+
return;
48+
}
49+
this.wasmSimulation.free();
50+
this.wasmSimulation = null;
51+
};
4452
}
4553

4654
export default new SimulationService();

packages/web/src/lib/stores/world.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,7 @@ export const stopWorldUpdates = () => {
4343
if (animationFrameId) {
4444
cancelAnimationFrame(animationFrameId);
4545
animationFrameId = null;
46+
worldStore.set(null);
47+
statsStore.set(null);
4648
}
4749
};

packages/web/src/routes/world/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ onMount(async () => {
1212
// Show connecting screen for fun
1313
setTimeout(() => {
1414
isLoading = false;
15-
}, 2000);
15+
}, 1000);
1616
});
1717
</script>
1818

0 commit comments

Comments
 (0)