Repository: 4ian/GDevelop
File: GDJS/Runtime/pixi-renderers/pixi-bitmapfont-manager.ts (TypeScript)

Code before:
      }
    }

    /**
     * To be called when the game is disposed.
     * Uninstall all the fonts from memory and clear cache of loaded fonts.
     */
    dispose(): void {
      for (const bitmapFontInstallKey in this._pixiBitmapFontsInUse) {
        PIXI.BitmapFont.uninstall(bitmapFontInstallKey);
      }

      for (const bitmapFontInstallKey of this._pixiBitmapFontsToUninstall) {
        PIXI.BitmapFont.uninstall(bitmapFontInstallKey);
      }

      this._pixiBitmapFontsInUse = {};
      this._pixiBitmapFontsToUninstall.length = 0;
      this._loadedFontsData.clear();
    }

    unloadResource(resourceData: ResourceData): void {
      this._loadedFontsData.delete(resourceData);

      for (const bitmapFontInstallKey in this._pixiBitmapFontsInUse) {
        if (bitmapFontInstallKey.startsWith(resourceData.name)) {
          PIXI.BitmapFont.uninstall(bitmapFontInstallKey);
          delete this._pixiBitmapFontsInUse[bitmapFontInstallKey];
        }
      }

      for (
        let index = 0;
        index < this._pixiBitmapFontsToUninstall.length;
        index++
      ) {
        const bitmapFontInstallKey = this._pixiBitmapFontsToUninstall[index];

        if (bitmapFontInstallKey.startsWith(resourceData.name)) {
          PIXI.BitmapFont.uninstall(bitmapFontInstallKey);
          this._pixiBitmapFontsToUninstall.splice(index, 1);
          index--;
        }
      }
    }
  }

  // Register the class to let the engine use it.
  export const BitmapFontManager = gdjs.PixiBitmapFontManager;
  export type BitmapFontManager = gdjs.PixiBitmapFontManager;
}

Review comment (suggestion):
I think that should be 
```suggestion
        if (bitmapFontInstallKey.startsWith(resourceData.name + '@')) {
```

to avoid issues when a resource name is a prefix of another (not that unlikely, it can happen if a resource name is "MyBitmapText" and another is "MyBitmapTextSpecial" or "MyBitmapText2", etc...)

Code after:
      }
    }

    /**
     * To be called when the game is disposed.
     * Uninstall all the fonts from memory and clear cache of loaded fonts.
     */
    dispose(): void {
      for (const bitmapFontInstallKey in this._pixiBitmapFontsInUse) {
        PIXI.BitmapFont.uninstall(bitmapFontInstallKey);
      }

      for (const bitmapFontInstallKey of this._pixiBitmapFontsToUninstall) {
        PIXI.BitmapFont.uninstall(bitmapFontInstallKey);
      }

      this._pixiBitmapFontsInUse = {};
      this._pixiBitmapFontsToUninstall.length = 0;
      this._loadedFontsData.clear();
    }

    unloadResource(resourceData: ResourceData): void {
      this._loadedFontsData.delete(resourceData);

      for (const bitmapFontInstallKey in this._pixiBitmapFontsInUse) {
        if (bitmapFontInstallKey.startsWith(resourceData.name + '@')) {
          PIXI.BitmapFont.uninstall(bitmapFontInstallKey);
          delete this._pixiBitmapFontsInUse[bitmapFontInstallKey];
        }
      }

      for (
        let index = 0;
        index < this._pixiBitmapFontsToUninstall.length;
        index++
      ) {
        const bitmapFontInstallKey = this._pixiBitmapFontsToUninstall[index];

        if (bitmapFontInstallKey.startsWith(resourceData.name + '@')) {
          PIXI.BitmapFont.uninstall(bitmapFontInstallKey);
          this._pixiBitmapFontsToUninstall.splice(index, 1);
          index--;
        }
      }
    }
  }

  // Register the class to let the engine use it.
  export const BitmapFontManager = gdjs.PixiBitmapFontManager;
  export type BitmapFontManager = gdjs.PixiBitmapFontManager;
}