excaliburjs / Excalibur

🎮 Your friendly TypeScript 2D game engine for the web 🗡️
https://excaliburjs.com
BSD 2-Clause "Simplified" License
1.81k stars 188 forks source link

Multiple Text objects using the same Font object overwrite each other #2411

Closed DaVince closed 2 years ago

DaVince commented 2 years ago

When creating more than 1 Label or Text that use the same Font, Excalibur gets confused and overwrites the contents of previous Labels. It also offsets the x positions of the Labels randomly.

image

Steps to Reproduce

Code example:

My code:

import pixelFont from "./assets/font/at01.ttf";
let Resources = {
  pixelFont: new Font({ family: 'pixel-font', size: 32, smoothing: false }),
};

class Game extends Engine {
  constructor() {
    super({
      width: 1280,
      height: 720,
      maxFps: 60,
      displayMode: DisplayMode.FillScreen
    });
  }
  initialize() {
    const loader = new Loader([]);
    this.start(loader).then(() => {
      const text = new Label({
        text: "hi!",
        pos: vec(0, 20),
        font: Resources.pixelFont
      });
      this.add(text);

      const text2 = new Label({
        text: "hi????!",
        pos: vec(0, 40),
        font: Resources.pixelFont
      });
      this.add(text2);
    });
  }
}

export const game = new Game();
game.initialize();

Expected Result

Two labels with their own relative text and positions should appear.

Actual Result

The two labels appear, but they both have the text from the last label created.

Environment

Current workaround

Creating a clone of the Font object with the .clone() method for each Label and Text object.

Additional information

Attached is the full output of one of the WebGL warnings that appears in the console: BindTexturesError.txt

This error also happens in Firefox, though the console message is worded differently:

WebGL warning: bindTexture: Object `tex` is already deleted.
eonarheim commented 2 years ago

@DaVince Thanks for the issue!

Definitely a bug! Feels like I've fixed this one before, you should be able to re-use the fonts as you expect.

eonarheim commented 2 years ago

Doh, definitely a regression I should have a fix up soon (with a better test to prevent this from happening again)

Related #2152

DaVince commented 2 years ago

Excellent, thanks so much!