Skip to content

Conversation

BOTDan
Copy link
Contributor

@BOTDan BOTDan commented Jun 4, 2025

Description of change

Resets the transform of contexts returned to the CanvasPool.

When creating DynamicBitmapFont, the canvas context used is scaled to match the resolution option supplied. If this font is later destroyed, the canvas and context are returned to the CanvasPool for potential re-use. If the context gets re-used, the previous scale is still present. So if the previous font had a resolution other than 1, the scale ends up incorrect.

Example: https://pixiplayground.com/#/edit/oz0ynP2N-YUMyLQ7ft1ae

In the example, the third font re-uses the canvas context from the second font, which already had a scale of 2, resulting in a scale of 4, and the font appearing incorrect.

I'm not sure if it's best to either reset the transform when returning the canvas, or to reset it before scaling in DynamicBitmapFont here.

context.scale(resolution, resolution);

But most things using the CanvasPool seem to assume the contexts are clean, so it probably makes sense to do it on return.

fixes #11392
(I think)

Pre-Merge Checklist
  • Tests and/or benchmarks are included
  • Lint process passed (npm run lint)
  • Tests passed (npm run test)

Copy link

codesandbox-ci bot commented Jun 4, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 59d71cd:

Sandbox Source
pixi.js-sandbox Configuration

@BOTDan BOTDan marked this pull request as ready for review June 4, 2025 20:30
Copy link
Member

@bigtimebuddy bigtimebuddy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense!

@Zyie Zyie added the ✅ Ready To Merge Helpful when issues are in the queue waiting to get merged. This means the PR is completed and has t label Jun 30, 2025
@Zyie Zyie added this pull request to the merge queue Jun 30, 2025
Merged via the queue into pixijs:dev with commit a0807be Jun 30, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✅ Ready To Merge Helpful when issues are in the queue waiting to get merged. This means the PR is completed and has t
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: When there is a resolution option, reinstalling BitmapFont will result in incorrect display.
4 participants