ImGui.NET icon indicating copy to clipboard operation
ImGui.NET copied to clipboard

Button with empty string as label crashes

Open Shadowblitz16 opened this issue 3 years ago • 2 comments

This crashes...

public class Button : Pressable
{
    protected override void OnRender(float dt)
    {
        base.OnRender(dt);

        var id = (Label == "" ? " " : Label) + "###" + GetHashCode();
        if (ImGui.Button(id)) // Crashes
            Pressed = true;
    }
}

This is where it reaches before terminating the program. image

Shadowblitz16 avatar Jul 27 '22 02:07 Shadowblitz16

What a code abortion :P var id = (Label == "" ? " " : Label) + "###" + GetHashCode();

Could have 'Label' as a nullable string, also why do you want it to start with white space if Label == string.Empty? var id = $"###{Label}{GetHashCode()}";

mbwilding avatar Jul 27 '22 12:07 mbwilding

What a code abortion :P var id = (Label == "" ? " " : Label) + "###" + GetHashCode();

Could have 'Label' as a nullable string, also why do you want it to start with white space if Label == string.Empty? var id = $"###{Label}{GetHashCode()}";

I thought the empty or null string was the problem. turns out it wasn't

Shadowblitz16 avatar Jul 29 '22 02:07 Shadowblitz16