[fix] freeze caused by unicode characters missing in font #22658
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.
(replacement of PR#22648, under my team account)
Description
Fixes the issue of unicode characters freezing Nexus.
When a unicode character does not exist in a font, Matrix showed the .notdef / box character instead.
In Nexus such characters are handled inconsistently, sometimes resulting in an exception / freeze.
GetTextWidthInternal() called by CGUIFontTTF::DrawTextInternal line 405, and the loop at line 462 take into account the space used by the .notdef/codepoint/glyph 0 characters to populate the "characters" queue.
However the block of line 495 pops the glyph without increasing cursorX so eventually the condition to stop the loop fails and the code attempts to dequeue too many times from the empty "characters" queue, causing an exception and the freeze.
This patch reverts to the behavior of Matrix and displays the .notdef / box characters for the unicode characters missing in the font.
Alternatively maybe they were skipped on purpose and the behavior change was incomplete? In that case additional changes are needed in GetTextWidthInternal and the loop of line 462 to skip the codepoint 0 characters.
Let me know which way you want to go.
Motivation and context
My case: Kodi v20 crashes with the skin Confluence and its default font roboto-regular when displaying file names that contain some unicode characters that don't exist in the font.
For example filename when dumping https://www.youtube.com/watch?v=BRAWVIX7mv0 with yt-dlp and browsing it in the Videos view.
The filename contains unicode 0xff1f, which does not exist in the roboto font.
Additional condition for the freeze: the text must be long enough to overflow the label. It would normally have some characters truncated + ellipsis(...) added at the end.
The same problem was reported by other users about emojis with default skin and font.
Solves issue 22473 and 22565 - maybe others?
Reported many times in the forums as well, usually in relation with the addons, especially the youtube addon.
How has this been tested?
Tested on Windows 10 x64.
Just in case some code was using the value 0 as a failure return code instead of the .notdef glyph, I set a conditional breakpoint and navigated casually through the various screens but nothing came up other than valid .notdef glyph uses.
What is the effect on users?
Fixes a freeze of Kodi when displaying some unicode characters.
Types of change
Checklist: