Skip to content

Commit

Permalink
fix: uninstalling bitmap font containing space characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Zyie committed May 23, 2024
1 parent 8bec73b commit c8d2fbc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/scene/text-bitmap/AbstractBitmapFont.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ export abstract class AbstractBitmapFont<FontType>

for (const i in this.chars)
{
this.chars[i].texture.destroy();
// texture may not exist if the char is " ", \n, \r, or \t.
this.chars[i].texture?.destroy();
}

(this.chars as null) = null;
Expand Down
9 changes: 9 additions & 0 deletions tests/renderering/text/BitmapFontManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ describe('BitmapFontManager', () =>
expect(bitmapFont).toBeDefined();
});

it('should uninstall and remove from Cache if char is empty', () =>
{
BitmapFontManager.install('foo', {}, { chars: ' ' });
expect(Cache.get<BitmapFont>('foo-bitmap')).toBeDefined();

BitmapFontManager.uninstall('foo');
expect(Cache.get<BitmapFont>('foo-bitmap')).toBeUndefined();
});

it('should uninstall and remove from Cache', () =>
{
BitmapFontManager.install('foo', {}, { chars: 'a' });
Expand Down

0 comments on commit c8d2fbc

Please sign in to comment.