Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
DaVince opened this issue Jul 13, 2022 · 3 comments · Fixed by #2413
Closed

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

DaVince opened this issue Jul 13, 2022 · 3 comments · Fixed by #2413

Comments

@DaVince
Copy link
Contributor

DaVince commented Jul 13, 2022

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

  • Create a font resource.
  • Create two Labels with different text and coordinates. Make them use the same font resource.
  • Add the labels to the scene and display the scene.

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

  • browsers and versions: Chrome 103.0.5060.114, Firefox 102.0.1
  • operating system: Ubuntu 21.10
  • Excalibur versions: 0.27.0, 0.26.0.
  • Regression happened between 0.25.0 and 0.26.0; the former does properly create two labels with their own text and proper offsets.

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
Copy link
Member

@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
Copy link
Member

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

Related #2152

eonarheim added a commit that referenced this issue Jul 16, 2022
…2413)

Closes #2411

## Changes:

- Refactor font to be simpler and use a separate state container for each text instance
@DaVince
Copy link
Contributor Author

DaVince commented Jul 16, 2022

Excellent, thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants