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

MenuBar (without children) causes stack overflow when shortcut is pressed #2750

Closed
oh-hi opened this issue Jul 16, 2023 · 2 comments · Fixed by #2754
Closed

MenuBar (without children) causes stack overflow when shortcut is pressed #2750

oh-hi opened this issue Jul 16, 2023 · 2 comments · Fixed by #2754
Labels

Comments

@oh-hi
Copy link

oh-hi commented Jul 16, 2023

Describe the bug
Shift + Spacebar results in a stack overflow exception.

To Reproduce
Press SHIFT + SPACE anytime in the terminal application.
looks like it comes from FindAndOpenMenuByShortcut calling itself recursively.

Expected behavior
No behavior is expected.
This is just the result of accidentally causing the bug while typing.

Additional context
I am using Windows 10, 22H2
Terminal.Gui version 1.12.1

Here is the call stack (image)

716

@BDisp
Copy link
Collaborator

BDisp commented Jul 17, 2023

I can't reproduce this with none of the drivers. Perhaps is caused by some implementation in your app. Can you provide a sample which throw the exception using the behavior you've described, please. Thanks.

@tig tig added the bug label Jul 17, 2023
@oh-hi
Copy link
Author

oh-hi commented Jul 17, 2023

Ok, I found the Issue. I use a menubar as a button bar to interface with a ListView like so:
Capture

While debugging I found the only reason I would get a stack overflow is because none of these MenuBarItems have children. This causes FindAndOpenMenuByShortcut to overflow. Here is a sample that throws the exception when any key is pressed in the application.

using Terminal.Gui;

namespace Test
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Application.Init();

            MenuBarItem MenuTitle = new MenuBarItem("[Conditions]", "", null);
            MenuBarItem NewComparison = new MenuBarItem("New...", "", null);
            MenuBarItem EditComparison = new MenuBarItem("Edit..", "", null);
            MenuBarItem RemoveComparison = new MenuBarItem("Remove", "", null);

            MenuBar ConditionControls = new MenuBar(new MenuBarItem[]{
                MenuTitle,
                NewComparison,
                EditComparison,
                RemoveComparison
            })
            {
                X = 0,
                Y = 0,
                ColorScheme = new ColorScheme
                {
                    Normal = Terminal.Gui.Attribute.Make(Color.White, Color.DarkGray),
                    Focus = Terminal.Gui.Attribute.Make(Color.White, Color.DarkGray)
                }
            };

            Application.Top.Add(ConditionControls);

            Application.Run();
        }
    }
}

I understand this is not the proper use for this object, but it does look cool.

@oh-hi oh-hi changed the title Shift +Spacebar causes stack overflow exception MenuBar (without children) causes stack overflow when shortcut is pressed Jul 17, 2023
BDisp added a commit to BDisp/Terminal.Gui that referenced this issue Jul 19, 2023
BDisp added a commit to BDisp/Terminal.Gui that referenced this issue Jul 19, 2023
@tig tig closed this as completed in #2754 Jul 19, 2023
tig pushed a commit that referenced this issue Jul 19, 2023
tig pushed a commit that referenced this issue Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants