From 7134b221fdfbe8151ca50384b16e3106024c6aea Mon Sep 17 00:00:00 2001 From: cale bradbury Date: Fri, 6 Dec 2024 00:17:10 -0500 Subject: [PATCH 1/2] Add try catch when initializing user code --- packages/engine/src/HedronEngine.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/engine/src/HedronEngine.ts b/packages/engine/src/HedronEngine.ts index 975084cd..c6886d40 100644 --- a/packages/engine/src/HedronEngine.ts +++ b/packages/engine/src/HedronEngine.ts @@ -36,7 +36,11 @@ export class HedronEngine { public async initiateSketchModules(moduleIds: string[]) { for (const moduleId of moduleIds) { - await this.addSketchModule(moduleId) + try { + await this.addSketchModule(moduleId) + } catch (error) { + console.error('Init error in: ' + moduleId, error) + } } this.store.setState({ isSketchModulesReady: true }) From 3f0a13bd0abb73dc8b89b7965ee328be8034c19a Mon Sep 17 00:00:00 2001 From: cale bradbury Date: Fri, 6 Dec 2024 01:00:16 -0500 Subject: [PATCH 2/2] Search for post effects and handle their removal as rootless sketches --- packages/engine/src/HedronEngine.ts | 1 + packages/engine/src/world/EngineScene.ts | 8 ++++++++ packages/engine/src/world/SketchManager.ts | 13 ++++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/engine/src/HedronEngine.ts b/packages/engine/src/HedronEngine.ts index c6886d40..49560e5d 100644 --- a/packages/engine/src/HedronEngine.ts +++ b/packages/engine/src/HedronEngine.ts @@ -112,6 +112,7 @@ export class HedronEngine { if (instance.getPasses) { instance.getPasses(debugScene).forEach((pass) => { + pass.name = sketch.id debugScene.addPass(pass) }) } diff --git a/packages/engine/src/world/EngineScene.ts b/packages/engine/src/world/EngineScene.ts index 33da678a..0750f8a1 100644 --- a/packages/engine/src/world/EngineScene.ts +++ b/packages/engine/src/world/EngineScene.ts @@ -25,7 +25,15 @@ export class EngineScene { this.passes.push(pass) } + removePass(pass: Pass): void { + this.passes = this.passes.filter((p) => p !== pass) + } + clearPasses(): void { this.passes = [this.renderPass] } + + getPassesByName(name: string): Pass[] { + return this.passes.filter((pass) => pass.name === name) + } } diff --git a/packages/engine/src/world/SketchManager.ts b/packages/engine/src/world/SketchManager.ts index 6a7314c1..34677d76 100644 --- a/packages/engine/src/world/SketchManager.ts +++ b/packages/engine/src/world/SketchManager.ts @@ -35,14 +35,21 @@ export class SketchManager { } public removeSketchFromScene = (instanceId: string): void => { - const scene = getDebugScene().scene - const oldSketch = scene.getObjectByName(instanceId) + const engineScene = getDebugScene() + const threeScene = engineScene.scene + const oldSketch = threeScene.getObjectByName(instanceId) if (!oldSketch) { + const pass = engineScene.getPassesByName(instanceId) + if (pass?.length) { + pass.forEach((p) => engineScene.removePass(p)) + delete this.sketchInstances[instanceId] + return + } throw new Error(`couldn't find sketch to remove: ${instanceId}`) } - scene.remove(oldSketch) + threeScene.remove(oldSketch) delete this.sketchInstances[instanceId] }