rds1983 / Myra

UI Library for MonoGame, FNA and Stride
MIT License
703 stars 94 forks source link

Crash: pasting 💁👌🎍😍 in a textbox crashes #446

Closed NinthDesertDude closed 6 months ago

NinthDesertDude commented 6 months ago

Repro using this string: 💁👌🎍😍

In TextChunk.cs, this is the problematic function:

public TextChunkGlyph? GetGlyphInfoByIndex(int index)
{
    if (string.IsNullOrEmpty(Text) || index < 0 || index >= Text.Length)
    {
        return null;
    }
    return Glyphs[index];

We have index = 7 because each emoji is composed of 2 characters due to being Unicode. Text.Length is 8. Glyphs is an array of size 4, because it's from FontStashSharp and they know we only have 4 characters here. We're trying to access index 7 in Glyphs, so we get System.ArgumentOutOfRangeException: 'Index was out of range.'

rds1983 commented 6 months ago

wondering, would it work in Label?

NinthDesertDude commented 6 months ago

@rds1983 It's blank, it doesn't display the text but it does not crash.

rds1983 commented 6 months ago

yeah, probably default font ttf simply doesnt have glyphs for it

NinthDesertDude commented 6 months ago

Updated with the exact issue in source code. Hopefully FontStashSharp has a way to read the number of characters that're in a codepoint, because all navigation in the textbox would have to start doing that to deal with this scenario...alternatively, handle this crash by rejecting typed or pasted content that would result in Text.Length not matching the Glyphs array size (basically forcing glyph to be only one character long) until generic Unicode support can be done.

rds1983 commented 6 months ago

Should be fixed after updating to FSS 1.3.5