fix: reset transform when returning canvas to CanvasPool #11460
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of change
Resets the transform of contexts returned to the
CanvasPool
.When creating
DynamicBitmapFont
, the canvas context used is scaled to match theresolution
option supplied. If this font is later destroyed, the canvas and context are returned to theCanvasPool
for potential re-use. If the context gets re-used, the previous scale is still present. So if the previous font had aresolution
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.pixijs/src/scene/text-bitmap/DynamicBitmapFont.ts
Line 368 in 40dbf24
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
npm run lint
)npm run test
)