@@ -379,7 +379,16 @@ export abstract class BaseRenderLayer extends Disposable implements IRenderLayer
379379 }
380380 this . _ctx . save ( ) ;
381381 this . _clipRow ( y ) ;
382+
382383 // Draw the image, use the bitmap if it's available
384+
385+ // HACK: If the canvas doesn't match, delete the generator. It's not clear how this happens but
386+ // something is wrong with either the lifecycle of _bitmapGenerator or the page canvases are
387+ // swapped out unexpectedly
388+ if ( this . _bitmapGenerator [ glyph . texturePage ] && this . _charAtlas . pages [ glyph . texturePage ] . canvas !== this . _bitmapGenerator [ glyph . texturePage ] ! . canvas ) {
389+ delete this . _bitmapGenerator [ glyph . texturePage ] ;
390+ }
391+
383392 if ( this . _charAtlas . pages [ glyph . texturePage ] . version !== this . _bitmapGenerator [ glyph . texturePage ] ?. version ) {
384393 if ( ! this . _bitmapGenerator [ glyph . texturePage ] ) {
385394 this . _bitmapGenerator [ glyph . texturePage ] = new BitmapGenerator ( this . _charAtlas . pages [ glyph . texturePage ] . canvas ) ;
@@ -446,11 +455,12 @@ class BitmapGenerator {
446455 public get bitmap ( ) : ImageBitmap | undefined { return this . _bitmap ; }
447456 public version : number = - 1 ;
448457
449- constructor ( private readonly _canvas : HTMLCanvasElement ) {
458+ constructor ( public readonly canvas : HTMLCanvasElement ) {
450459 }
451460
452461 public refresh ( ) : void {
453462 // Clear the bitmap immediately as it's stale
463+ this . _bitmap ?. close ( ) ;
454464 this . _bitmap = undefined ;
455465 // Disable ImageBitmaps on Safari because of https://bugs.webkit.org/show_bug.cgi?id=149990
456466 if ( isSafari ) {
@@ -466,9 +476,10 @@ class BitmapGenerator {
466476
467477 private _generate ( ) : void {
468478 if ( this . _state === BitmapGeneratorState . IDLE ) {
479+ this . _bitmap ?. close ( ) ;
469480 this . _bitmap = undefined ;
470481 this . _state = BitmapGeneratorState . GENERATING ;
471- window . createImageBitmap ( this . _canvas ) . then ( bitmap => {
482+ window . createImageBitmap ( this . canvas ) . then ( bitmap => {
472483 if ( this . _state === BitmapGeneratorState . GENERATING_INVALID ) {
473484 this . refresh ( ) ;
474485 } else {
0 commit comments