Menu bug, stack overflow

Hello together I’m back with some new problems ^^’

As part of the use I’ll be able to show context menus. I’ve see that tonegod has an nice class Menu which supports sub menu’s. But after a few tests it just looks bugged.

When I initialize a Menu on the following way:

Vector2f cursorPosition2D = app.getInputManager().getCursorPosition();
Menu menu = new Menu(screen, UIDUtil.getUID(), Vector2f.ZERO, screen.getStyle("Menu").getVector2f("defaultSize"), screen.getStyle("Menu").getVector4f("resizeBorders"), "Interface/defaultImg/panelDefaultImageDark.png", false) {
    public void onMenuItemClicked(int index, Object value, boolean isToggled) { }

menu.addMenuItem("Test", 0, null);
menu.showMenu(menu, cursorPosition2D.x, cursorPosition2D.y);

The Menu shows up fine with one content which has the caption “Test”. But when I click on it, an stack overflow error occur. I’ve evaluated that the error comes from that the Menu after the click want to close sub menu’s (hasSubMenu is set to true) even if there isn’t any sub menu set (look upside the code). In cause of that the method calls itself as long as the stack overflows.

If I made any mistake tell me :slight_smile: I just want to have to ask for any known buggs before programming it by myself again :smiley:


This looks as if you are setting the menu’s parent menu to itself… which would cause the above issue. Try passing in null instead of menu when calling showMenu.


I thought I’ve seen this method in any tutorial but I can’t find it anymore xD

Another question:
When I open the Menu near the right side of the screen and it would go over the end of the screen. It resets it’s position X position to 0
E.g.: Menu Position (X: 700, Y: 300), Menu Dimension (X: 150, Y: 20), Screen Resolution: (X: 800, Y: 600) = New Menu Position (X: 0, Y: 300) (Because 700 + 150 > 800)
don’t know if this happens in the Y-Axis as well