@esotericsoftware/spine-canvas 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.
@@ -5787,7 +5787,7 @@ var spine = (() => {
5787
5787
  return blob ? createImageBitmap(blob, { premultiplyAlpha: "none", colorSpaceConversion: "none" }) : null;
5788
5788
  }).then((bitmap) => {
5789
5789
  if (bitmap) {
5790
- const texture = this.textureLoader(bitmap);
5790
+ const texture = this.createTexture(path, bitmap);
5791
5791
  this.success(success, path, texture);
5792
5792
  resolve(texture);
5793
5793
  }
@@ -5797,7 +5797,7 @@ var spine = (() => {
5797
5797
  let image = new Image();
5798
5798
  image.crossOrigin = "anonymous";
5799
5799
  image.onload = () => {
5800
- const texture = this.textureLoader(image);
5800
+ const texture = this.createTexture(path, image);
5801
5801
  this.success(success, path, texture);
5802
5802
  resolve(texture);
5803
5803
  };
@@ -5821,7 +5821,7 @@ var spine = (() => {
5821
5821
  this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
5822
5822
  this.downloader.downloadText(path, (atlasText) => {
5823
5823
  try {
5824
- let atlas = new TextureAtlas(atlasText);
5824
+ const atlas = this.createTextureAtlas(path, atlasText);
5825
5825
  let toLoad = atlas.pages.length, abort = false;
5826
5826
  for (let page of atlas.pages) {
5827
5827
  this.loadTexture(
@@ -5865,7 +5865,7 @@ var spine = (() => {
5865
5865
  this.cache.assetsLoaded[path] = new Promise((resolve, reject) => {
5866
5866
  this.downloader.downloadText(path, (atlasText) => {
5867
5867
  try {
5868
- const atlas = new TextureAtlas(atlasText);
5868
+ const atlas = this.createTextureAtlas(path, atlasText);
5869
5869
  this.success(success, path, atlas);
5870
5870
  resolve(atlas);
5871
5871
  } catch (e) {
@@ -5971,9 +5971,12 @@ var spine = (() => {
5971
5971
  }
5972
5972
  // dispose asset only if it's not used by others
5973
5973
  disposeAsset(path) {
5974
- if (--this.cache.assetsRefCount[path] === 0) {
5975
- this.remove(path);
5974
+ const asset = this.cache.assets[path];
5975
+ if (asset instanceof TextureAtlas) {
5976
+ asset.dispose();
5977
+ return;
5976
5978
  }
5979
+ this.disposeAssetInternal(path);
5977
5980
  }
5978
5981
  hasErrors() {
5979
5982
  return Object.keys(this.errors).length > 0;
@@ -5981,6 +5984,30 @@ var spine = (() => {
5981
5984
  getErrors() {
5982
5985
  return this.errors;
5983
5986
  }
5987
+ disposeAssetInternal(path) {
5988
+ if (this.cache.assetsRefCount[path] > 0 && --this.cache.assetsRefCount[path] === 0) {
5989
+ return this.remove(path);
5990
+ }
5991
+ }
5992
+ createTextureAtlas(path, atlasText) {
5993
+ const atlas = new TextureAtlas(atlasText);
5994
+ atlas.dispose = () => {
5995
+ if (this.cache.assetsRefCount[path] <= 0) return;
5996
+ this.disposeAssetInternal(path);
5997
+ for (const page of atlas.pages) {
5998
+ page.texture?.dispose();
5999
+ }
6000
+ };
6001
+ return atlas;
6002
+ }
6003
+ createTexture(path, image) {
6004
+ const texture = this.textureLoader(image);
6005
+ const textureDispose = texture.dispose.bind(texture);
6006
+ texture.dispose = () => {
6007
+ if (this.disposeAssetInternal(path)) textureDispose();
6008
+ };
6009
+ return texture;
6010
+ }
5984
6011
  };
5985
6012
  var AssetCache = class _AssetCache {
5986
6013
  assets = {};