@preference-sl/pref-viewer 2.13.0 → 2.13.1-beta.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@preference-sl/pref-viewer",
3
- "version": "2.13.0",
3
+ "version": "2.13.1-beta.0",
4
4
  "description": "Web Component to preview GLTF models with Babylon.js",
5
5
  "author": "Alex Moreno Palacio <amoreno@preference.es>",
6
6
  "scripts": {
@@ -1224,6 +1224,7 @@ export default class BabylonJSController {
1224
1224
  * @returns {void}
1225
1225
  */
1226
1226
  #setMaxSimultaneousLights() {
1227
+ if (!this.#scene) return;
1227
1228
  let lightsNumber = 1; // At least one light coming from the environment texture contribution
1228
1229
  this.#scene.lights.forEach((light) => {
1229
1230
  if (light.isEnabled()) {
@@ -1917,6 +1918,12 @@ export default class BabylonJSController {
1917
1918
  container.assetContainer.dispose();
1918
1919
  container.assetContainer = null;
1919
1920
  }
1921
+ if (!this.#scene) {
1922
+ // Scene was disposed (disconnect) while async loading was in progress; discard the
1923
+ // newly loaded container so we don't leak GPU resources and avoid the null-deref below.
1924
+ newAssetContainer?.dispose();
1925
+ return false;
1926
+ }
1920
1927
  this.#scene.getEngine().releaseEffects();
1921
1928
  this.#scene.getEngine().releaseComputeEffects();
1922
1929
 
@@ -2004,6 +2011,7 @@ export default class BabylonJSController {
2004
2011
  * @returns {Promise<void>}
2005
2012
  */
2006
2013
  async #startRender() {
2014
+ if (!this.#scene) return;
2007
2015
  await this.#loadCameraDependentEffects();
2008
2016
  await this.#scene.whenReadyAsync();
2009
2017
  const frames = this.#settings.antiAliasingEnabled || this.#settings.ambientOcclusionEnabled || this.#settings.iblEnabled ? this.#config.render.burstFramesEnhanced : this.#config.render.burstFramesBase;
@@ -2105,6 +2113,13 @@ export default class BabylonJSController {
2105
2113
 
2106
2114
  await Promise.allSettled(promiseArray)
2107
2115
  .then(async (values) => {
2116
+ // Scene may have been disposed (disconnectedCallback) while async loading was in
2117
+ // progress. Abort cleanly: #replaceContainer already guards the GPU calls, but
2118
+ // we skip the post-load option/visibility calls too to avoid further null-derefs.
2119
+ if (!this.#scene) {
2120
+ values.forEach((result) => { result.value?.[1]?.dispose(); });
2121
+ return;
2122
+ }
2108
2123
  this.#disposeAnimationController();
2109
2124
  values.forEach((result) => {
2110
2125
  const container = result.value ? result.value[0] : null;