Fix glyph cache crash #820
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.
Synopsis
Fixes #815. The
Style::with_font
method clones the received font and then changes it, placing a different atlas pointer in the cloned font. It, however, doesn't do anything with thecharacters
field.Because of that, if the original font caches more glyphs -- the font passed to
Style::with_font
ends up in an inconsistent state, which leads to either crashed or garbage looking graphics. This happens from very naive things like measuring text after construing aStyle
, so I think it's worth fixing.The fix worked when I tested it against the example in issue #815.
The Fix
I simply modified the routine to supply the cloned font with its own
characters
map. To do this I also had to add apub(crate)
method for settingcharacters
.Alternatives
The alternative is to stop giving the cloned font a different atlas. But it looked like it might be against the original intention behind
Style
's design.