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

Fix on-demand glyph loading #4779

Merged

Conversation

vakhoir
Copy link
Contributor

@vakhoir vakhoir commented Jan 29, 2020

Fixes #4778

For all the talk in the issue, the fix seems relatively simple, the following description is also in the commit message:

Change the approach to checking if a font can handle a glyph. The original approach was to pass the valid glyph range to the constructor. When it's not found by ImGui we call AddGlyph where we check if it's valid for the font. In the event where ImGui couldn't handle a glyph that was defined as valid in the constructor, that led to constant re-baking of fonts. The new approach is to change m_ranges (which used to contain valid glyph ranges) to m_invalid_glyphs, which contains only invalid glyphs that we tried to add to the font but failed. The next time AddGlyph is called, we skip the font since it's unable to handle the glyph.

But I have to say, I'm not entirely confident about what I did here. @ecraven I think you're the one that wrote all this, I also saw an issue you opened in the ImGui repo, is there any chance you can chime in on this?

Copy link
Member

@Web-eWorks Web-eWorks left a comment

Choose a reason for hiding this comment

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

Looks pretty good to me at a first glance; I'll try to find the time to dig deeper into it soon and back up @ecraven's review.

One thing stands out to me; is there a reason for using std::unordered_map over std::unordered_set? Since we're mapping the glyph value to the... glyph value, it seems the latter might be the wiser choice here? AFAIK there's no particular difference in time complexity or performance.

src/PiGui.cpp Outdated Show resolved Hide resolved
@vakhoir vakhoir force-pushed the bugfix/font_bake_memory_leak branch from a095480 to 13a161f Compare January 30, 2020 18:03
Rename containsGlyph to isValidGlyph
Change the approach to checking if a font can handle a glyph. The original approach was to pass the valid glyph range to the constructor. When it's not found by ImGui we call AddGlyph where we check if it's valid for the font. In the event where ImGui couldn't handle a glyph that was defined as valid in the constructor, that led to constant re-baking of fonts. The new approach is to change m_ranges (which used to contain valid glyph ranges) to m_invalid_glyphs, which contains only invalid glyphs that we tried to add to the font but failed. The next time AddGlyph is called, we skip the font since it's unable to handle the glyph.
@Web-eWorks
Copy link
Member

Alright, I'll pull this PR locally in about twelve hours and try to dig into it to double-check everything is working. Thank you @vakhoir for this bugfixing (and bugfinding too!)

@Web-eWorks Web-eWorks merged commit 8ff5080 into pioneerspacesim:master Feb 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug in font charset detection causing memory leak
2 participants