@esotericsoftware/spine-phaser-v3 4.2.93 → 4.2.95

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.
@@ -5874,7 +5874,7 @@ var spine = (() => {
5874
5874
  return blob ? createImageBitmap(blob, { premultiplyAlpha: "none", colorSpaceConversion: "none" }) : null;
5875
5875
  }).then((bitmap) => {
5876
5876
  if (bitmap) {
5877
- const texture = this.textureLoader(bitmap);
5877
+ const texture = this.createTexture(path, bitmap);
5878
5878
  this.success(success, path, texture);
5879
5879
  resolve(texture);
5880
5880
  }
@@ -5884,7 +5884,7 @@ var spine = (() => {
5884
5884
  let image = new Image();
5885
5885
  image.crossOrigin = "anonymous";
5886
5886
  image.onload = () => {
5887
- const texture = this.textureLoader(image);
5887
+ const texture = this.createTexture(path, image);
5888
5888
  this.success(success, path, texture);
5889
5889
  resolve(texture);
5890
5890
  };
@@ -5908,7 +5908,7 @@ var spine = (() => {
5908
5908
  this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
5909
5909
  this.downloader.downloadText(path, (atlasText) => {
5910
5910
  try {
5911
- let atlas = new TextureAtlas(atlasText);
5911
+ const atlas = this.createTextureAtlas(path, atlasText);
5912
5912
  let toLoad = atlas.pages.length, abort = false;
5913
5913
  for (let page of atlas.pages) {
5914
5914
  this.loadTexture(
@@ -5952,7 +5952,7 @@ var spine = (() => {
5952
5952
  this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
5953
5953
  this.downloader.downloadText(path, (atlasText) => {
5954
5954
  try {
5955
- const atlas = new TextureAtlas(atlasText);
5955
+ const atlas = this.createTextureAtlas(path, atlasText);
5956
5956
  this.success(success, path, atlas);
5957
5957
  resolve(atlas);
5958
5958
  } catch (e) {
@@ -6058,9 +6058,12 @@ var spine = (() => {
6058
6058
  }
6059
6059
  // dispose asset only if it's not used by others
6060
6060
  disposeAsset(path) {
6061
- if (--this.cache.assetsRefCount[path] === 0) {
6062
- this.remove(path);
6061
+ const asset = this.cache.assets[path];
6062
+ if (asset instanceof TextureAtlas) {
6063
+ asset.dispose();
6064
+ return;
6063
6065
  }
6066
+ this.disposeAssetInternal(path);
6064
6067
  }
6065
6068
  hasErrors() {
6066
6069
  return Object.keys(this.errors).length > 0;
@@ -6068,6 +6071,30 @@ var spine = (() => {
6068
6071
  getErrors() {
6069
6072
  return this.errors;
6070
6073
  }
6074
+ disposeAssetInternal(path) {
6075
+ if (this.cache.assetsRefCount[path] > 0 && --this.cache.assetsRefCount[path] === 0) {
6076
+ return this.remove(path);
6077
+ }
6078
+ }
6079
+ createTextureAtlas(path, atlasText) {
6080
+ const atlas = new TextureAtlas(atlasText);
6081
+ atlas.dispose = () => {
6082
+ if (this.cache.assetsRefCount[path] <= 0) return;
6083
+ this.disposeAssetInternal(path);
6084
+ for (const page of atlas.pages) {
6085
+ page.texture?.dispose();
6086
+ }
6087
+ };
6088
+ return atlas;
6089
+ }
6090
+ createTexture(path, image) {
6091
+ const texture = this.textureLoader(image);
6092
+ const textureDispose = texture.dispose.bind(texture);
6093
+ texture.dispose = () => {
6094
+ if (this.disposeAssetInternal(path)) textureDispose();
6095
+ };
6096
+ return texture;
6097
+ }
6071
6098
  };
6072
6099
  var AssetCache = class _AssetCache {
6073
6100
  assets = {};
@@ -14951,7 +14978,9 @@ void main () {
14951
14978
  textures.push(line);
14952
14979
  }
14953
14980
  }
14954
- let basePath = (file.src.match(/^.*\//) ?? "").toString();
14981
+ let fileUrl = file.url;
14982
+ if (typeof fileUrl === "object") fileUrl = file.src;
14983
+ let basePath = (fileUrl.match(/^.*\//) ?? "").toString();
14955
14984
  if (this.loader.path && this.loader.path.length > 0 && basePath.startsWith(this.loader.path))
14956
14985
  basePath = basePath.slice(this.loader.path.length);
14957
14986
  for (var i = 0; i < textures.length; i++) {