Closed bug report

Model replacement guidance: repeated loadModel retained old harness meshes in vendored viewer

John Lauer · ·closed by Colby Knox

In the electronic-load review, calling viewer.loadModel(newUrl) on an existing viewer left old sensor-wire meshes in the scene alongside the new model. A clean page initialization removed them. This produced visibly doubled harnesses and can compound memory use.

Local vendored bundle: control-panel/twin/vendor/3d-viewer/adom-3d-viewer-babylon9.esm.js in adom-custom-electronic-load. Runtime namespace Adom3DViewerBabylon9. Exact release of this vendored bundle still needs comparison with current owner source; not claiming the latest release is affected.

Evidence: exported v8-full.glb and v8-copper.glb contain no NTC wires; v8-mechanics.glb and v8-review.glb contain only Heatsink_NTC_wire_1 and _2. After repeated loadModel, runtime scene also contained old Heatsink_NTC_wire_sense/return primitives. After full page reload:0 old sensor primitives,26 new primitives (13 per conductor), matching the current export.

Please document whether loadModel is intentionally additive. Provide/advertise an explicit replacement API that disposes prior model containers, animation groups, layer inventory and material/texture resources, while preserving viewer controls. Add repeated replacement tests. An additive import should be explicit. Local mitigation is one clean initialization in the existing task tab, not opening another viewer. No shared source fix/release/deployment is claimed.

1 Reply

Colby Knox ·

Shipped in 0.10.0 (published here; source 94986ab).

Is loadModel additive? Yes, by design: a second loadModel() adds to the scene, which is how the old harness meshes stayed next to the new export. It stays additive so hosts that compose a scene from several files keep working, and it is now documented as such.

Replacement API:

  • replaceModel(url) / replaceModelBytes(bytes, { extension }): the new model loads first, then every earlier model is disposed with everything it brought (meshes, materials, textures, animation groups, skeletons, content lights, layer and state-group inventory). Camera, controls, ground, environment and anything added with addContentRoot stay. If the load fails, the current model stays; of two overlapping calls, the later wins.
  • addModel(url) / addModelBytes(...): the explicitly additive names.
  • clearScene() now releases materials, textures, animation groups and skeletons too (it used to dispose only the mesh tree).

While testing, one more leak turned up and is fixed: the ground's material and fade texture leaked one of each on every model load or reframe.

Tests: test/replace.test.mjs (npm run test:replace) checks additive vs replace, that repeated replacement keeps scene mesh/material/texture counts flat, the bytes path, overlapping calls, a failed load, and clearScene.

For the electronic-load control panel: update the vendored bundle to 0.10.0 (release asset adom-3d-viewer-babylon9-0.10.0.tar.gz) and switch the reload call to viewer.replaceModel(newUrl).

Colby Knox closed this ·

Log in to reply.