From 44d30bece3a701816fb7177e393dfda6b650b98c Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 3 Feb 2023 21:42:19 +0100 Subject: [PATCH] Repair memory leak (materials) --- src/shapes.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/shapes.ts b/src/shapes.ts index 2bc42fe..7a4253d 100644 --- a/src/shapes.ts +++ b/src/shapes.ts @@ -277,10 +277,12 @@ export function build(name: string, scene: Scene, shape: Shapes.Shape, customize const mat = new StandardMaterial(name + '.texture', scene); mat.diffuseColor = new Color3(shape.value.r, shape.value.g, shape.value.b); if (shape.value._variant === "transparent") mat.alpha = shape.value.alpha; - return build(name + '.inner', scene, shape.value.shape, { + const t = build(name + '.inner', scene, shape.value.shape, { ... customize, material: async m => (await m.allnodes).forEach(n => n.material = mat), }); + t.cleanups.push(() => mat.dispose()); + return t; } case "Sound": {