@esotericsoftware/spine-phaser-v3 4.2.92 → 4.2.94

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.
@@ -5651,7 +5651,7 @@ var AssetManagerBase = class {
5651
5651
  return blob ? createImageBitmap(blob, { premultiplyAlpha: "none", colorSpaceConversion: "none" }) : null;
5652
5652
  }).then((bitmap) => {
5653
5653
  if (bitmap) {
5654
- const texture = this.textureLoader(bitmap);
5654
+ const texture = this.createTexture(path, bitmap);
5655
5655
  this.success(success, path, texture);
5656
5656
  resolve(texture);
5657
5657
  }
@@ -5661,7 +5661,7 @@ var AssetManagerBase = class {
5661
5661
  let image = new Image();
5662
5662
  image.crossOrigin = "anonymous";
5663
5663
  image.onload = () => {
5664
- const texture = this.textureLoader(image);
5664
+ const texture = this.createTexture(path, image);
5665
5665
  this.success(success, path, texture);
5666
5666
  resolve(texture);
5667
5667
  };
@@ -5685,7 +5685,7 @@ var AssetManagerBase = class {
5685
5685
  this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
5686
5686
  this.downloader.downloadText(path, (atlasText) => {
5687
5687
  try {
5688
- let atlas = new TextureAtlas(atlasText);
5688
+ const atlas = this.createTextureAtlas(path, atlasText);
5689
5689
  let toLoad = atlas.pages.length, abort = false;
5690
5690
  for (let page of atlas.pages) {
5691
5691
  this.loadTexture(
@@ -5729,7 +5729,7 @@ var AssetManagerBase = class {
5729
5729
  this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
5730
5730
  this.downloader.downloadText(path, (atlasText) => {
5731
5731
  try {
5732
- const atlas = new TextureAtlas(atlasText);
5732
+ const atlas = this.createTextureAtlas(path, atlasText);
5733
5733
  this.success(success, path, atlas);
5734
5734
  resolve(atlas);
5735
5735
  } catch (e) {
@@ -5835,9 +5835,12 @@ var AssetManagerBase = class {
5835
5835
  }
5836
5836
  // dispose asset only if it's not used by others
5837
5837
  disposeAsset(path) {
5838
- if (--this.cache.assetsRefCount[path] === 0) {
5839
- this.remove(path);
5838
+ const asset = this.cache.assets[path];
5839
+ if (asset instanceof TextureAtlas) {
5840
+ asset.dispose();
5841
+ return;
5840
5842
  }
5843
+ this.disposeAssetInternal(path);
5841
5844
  }
5842
5845
  hasErrors() {
5843
5846
  return Object.keys(this.errors).length > 0;
@@ -5845,6 +5848,30 @@ var AssetManagerBase = class {
5845
5848
  getErrors() {
5846
5849
  return this.errors;
5847
5850
  }
5851
+ disposeAssetInternal(path) {
5852
+ if (this.cache.assetsRefCount[path] > 0 && --this.cache.assetsRefCount[path] === 0) {
5853
+ return this.remove(path);
5854
+ }
5855
+ }
5856
+ createTextureAtlas(path, atlasText) {
5857
+ const atlas = new TextureAtlas(atlasText);
5858
+ atlas.dispose = () => {
5859
+ if (this.cache.assetsRefCount[path] <= 0) return;
5860
+ this.disposeAssetInternal(path);
5861
+ for (const page of atlas.pages) {
5862
+ page.texture?.dispose();
5863
+ }
5864
+ };
5865
+ return atlas;
5866
+ }
5867
+ createTexture(path, image) {
5868
+ const texture = this.textureLoader(image);
5869
+ const textureDispose = texture.dispose.bind(texture);
5870
+ texture.dispose = () => {
5871
+ if (this.disposeAssetInternal(path)) textureDispose();
5872
+ };
5873
+ return texture;
5874
+ }
5848
5875
  };
5849
5876
  var AssetCache = class _AssetCache {
5850
5877
  assets = {};
@@ -11537,10 +11564,10 @@ var SkeletonRenderer = class _SkeletonRenderer {
11537
11564
  var ManagedWebGLRenderingContext = class {
11538
11565
  canvas;
11539
11566
  gl;
11540
- restorables = new Array();
11541
- constructor(canvasOrContext, contextConfig = { alpha: "true" }) {
11567
+ restorables = [];
11568
+ constructor(canvasOrContext, contextConfig = { alpha: true }) {
11542
11569
  if (!(canvasOrContext instanceof WebGLRenderingContext || typeof WebGL2RenderingContext !== "undefined" && canvasOrContext instanceof WebGL2RenderingContext)) {
11543
- let canvas = canvasOrContext;
11570
+ const canvas = canvasOrContext;
11544
11571
  this.gl = canvas.getContext("webgl2", contextConfig) || canvas.getContext("webgl", contextConfig);
11545
11572
  this.canvas = canvas;
11546
11573
  canvas.addEventListener("webglcontextlost", this.contextLostHandler);
@@ -11550,13 +11577,13 @@ var ManagedWebGLRenderingContext = class {
11550
11577
  this.canvas = this.gl.canvas;
11551
11578
  }
11552
11579
  }
11553
- contextLostHandler(e) {
11580
+ contextLostHandler = (e) => {
11554
11581
  if (e) e.preventDefault();
11555
- }
11556
- contextRestoredHandler(e) {
11582
+ };
11583
+ contextRestoredHandler = () => {
11557
11584
  for (let i = 0, n = this.restorables.length; i < n; i++)
11558
11585
  this.restorables[i].restore();
11559
- }
11586
+ };
11560
11587
  dispose() {
11561
11588
  this.canvas.removeEventListener("webglcontextlost", this.contextLostHandler);
11562
11589
  this.canvas.removeEventListener("webglcontextrestored", this.contextRestoredHandler);
@@ -11565,7 +11592,7 @@ var ManagedWebGLRenderingContext = class {
11565
11592
  this.restorables.push(restorable);
11566
11593
  }
11567
11594
  removeRestorable(restorable) {
11568
- let index = this.restorables.indexOf(restorable);
11595
+ const index = this.restorables.indexOf(restorable);
11569
11596
  if (index > -1) this.restorables.splice(index, 1);
11570
11597
  }
11571
11598
  };