Fix effect switching race: add async disposal guards and scene cleanup to prevent stray meshes (#175)

This commit is contained in:
kali
2025-09-23 02:26:00 -03:00
committed by GitHub
parent 2ec7d706a1
commit 6317006ef3
5 changed files with 32 additions and 6 deletions
+3 -1
View File
@@ -5,6 +5,7 @@ import { getAssetFileURL } from "/examples/js/get-asset-url.js";
export async function init({ THREE: _THREE, scene, camera, renderer, spark }) {
const group = new THREE.Group();
scene.add(group);
let disposed = false;
// Camera baseline for Morph effect
camera.position.set(0, 2.2, 6.5);
@@ -169,7 +170,7 @@ export async function init({ THREE: _THREE, scene, camera, renderer, spark }) {
mesh.rotateX(Math.PI);
mesh.position.set(0, 0, 0);
mesh.scale.set(1.5, 1.5, 1.5);
group.add(mesh);
if (!disposed) group.add(mesh);
meshes.push(mesh);
}
@@ -219,6 +220,7 @@ export async function init({ THREE: _THREE, scene, camera, renderer, spark }) {
}
function dispose() {
disposed = true;
scene.remove(group);
}