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