From 8a7c8597daa1f66d6109a1b023bbaf4be526467f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 6 Mar 2024 16:58:41 +0100 Subject: [PATCH] Add Teardown code --- src/components/3d/PublicPreview.svelte | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/3d/PublicPreview.svelte b/src/components/3d/PublicPreview.svelte index 46ae07a..26811da 100644 --- a/src/components/3d/PublicPreview.svelte +++ b/src/components/3d/PublicPreview.svelte @@ -37,6 +37,7 @@ let renderer: THREE.WebGLRenderer; let controls: OrbitControls; let light: THREE.AmbientLight; + let observer: ResizeObserver; onMount(() => { scene = new THREE.Scene(); @@ -70,7 +71,8 @@ light = new THREE.AmbientLight(0xffffff, 1); scene.add(light); - new ResizeObserver(handleResize).observe(div); + observer = new ResizeObserver(handleResize); + observer.observe(div); loaded = true; @@ -91,6 +93,9 @@ if (loaded) { loaded = false; + observer.unobserve(div); + observer.disconnect(); + renderer.dispose(); scene.clear(); light.dispose();