@umicat/three-sdk 0.16.0 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -315,15 +315,32 @@ export async function loadScene3D(scene3d, manifest, opts = {}) {
315
315
  dispose() {
316
316
  for (const m of mixers)
317
317
  m.stopAllAction();
318
+ // Textures were never freed here — only geometries/materials — because
319
+ // every prior consumer (a game) loads a scene once per session. The
320
+ // Scene Previewer (platform-ui) reloads on every click-to-a-different-
321
+ // scene and every manual refresh, so the leak that used to be
322
+ // session-lifetime now actually accumulates. A Set guards against
323
+ // disposing a texture twice when two materials share one (e.g. an
324
+ // atlas'd model).
325
+ const disposedTextures = new Set();
326
+ const disposeMaterial = (mat) => {
327
+ for (const value of Object.values(mat)) {
328
+ if (value instanceof THREE.Texture && !disposedTextures.has(value)) {
329
+ disposedTextures.add(value);
330
+ value.dispose();
331
+ }
332
+ }
333
+ mat.dispose();
334
+ };
318
335
  scene.traverse((o) => {
319
336
  const mesh = o;
320
337
  if (mesh.geometry)
321
338
  mesh.geometry.dispose();
322
339
  const mat = mesh.material;
323
340
  if (Array.isArray(mat))
324
- mat.forEach((m) => m.dispose());
325
- else
326
- mat?.dispose();
341
+ mat.forEach(disposeMaterial);
342
+ else if (mat)
343
+ disposeMaterial(mat);
327
344
  });
328
345
  },
329
346
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umicat/three-sdk",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
4
4
  "description": "Three.js runtime for Umicat games: the scene3d design format, its loader with physics, a kinematic character controller, and the Umicat platform via @umicat/platform-sdk.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",