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

Fix a menu recursion issue #471

Merged
merged 2 commits into from Jul 10, 2018

Conversation

@Arkshine
Copy link
Member

commented Dec 3, 2017

Reported by JusTGo: https://forums.alliedmods.net/showthread.php?t=275819.

This partially reverts https://bugs.alliedmods.net/show_bug.cgi?id=3199 (5cb07b9), a fix is to prevent a context where you would overwrite a default menu (such as buy menu), and once you move out of the zone where such default menu would appear, this essentially fucks up your custom menu in some ways.

By sending menuselect 10, this would normally set the player's m_iMenu member to 0, therefore avoiding a previous default menu to act. It's actually a fix specific to CS and which doesn't work on a player who is not yet fully joined (team + appearance applied) because m_iMenu is only set if you are either fully joined or not stuck in team/appearance menu.

Thre regression happens when you overwrite an initial menu when the player is not yet fully joined, once menuselect 10 is sent, the game will send again the default menu, and therefore an infinite loop happens. Typically, this should happen only with team and appearance menu.

The proposed fix is simply to use m_iMenu directly for CS only intead.

Here a small test plugin to reproduce the error:

#include <amxmodx>

public plugin_init()
{
    register_message(get_user_msgid("ShowMenu"), "OnShowMenu");
}

public OnShowMenu(msgid, dest, id)
{
    static menu_text[64];
    get_msg_arg_string(4, menu_text, charsmax(menu_text));

    if (contain(menu_text, "#Team_Select") >= 0)
    {
        MainMenu(id);
        return PLUGIN_HANDLED;
    }

    return PLUGIN_CONTINUE;
}

public MainMenu(id)
{
    new const menu = menu_create("Menu", "@HandlerMainMenu");
    menu_additem(menu, "Item");
    menu_display(id, menu);
}

@HandlerMainMenu(id, menu, item)
{
    if (++item == 1)
    {
        MainMenu(id);
    }

    menu_destroy(menu);

    return PLUGIN_HANDLED;
}
@Arkshine

This comment has been minimized.

Copy link
Member Author

commented Dec 3, 2017

@Nextra, if you don't mind.

@Arkshine Arkshine force-pushed the Arkshine:fix/recursion-show_menu branch from f6bfcb3 to 67b1ea1 Dec 5, 2017

@Arkshine

This comment has been minimized.

Copy link
Member Author

commented Jul 10, 2018

Should be fine.

@Arkshine Arkshine merged commit 387dc6a into alliedmodders:master Jul 10, 2018

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Arkshine added a commit to Arkshine/amxmodx that referenced this pull request Oct 27, 2018
Arkshine added a commit that referenced this pull request Nov 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.