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

CreateMenuEx, ..., DisplayMenu crash @ player disconnection # 1.12.0.7066 #2073

Open
ClaudiuHKS opened this issue Nov 2, 2023 · 1 comment

Comments

@ClaudiuHKS
Copy link

ClaudiuHKS commented Nov 2, 2023

1.12.0.7066

While looking at the menu and leaving the game server it crashes without any error logs. It's supposed to be throwing error logs instead. No error logs are thrown while using the plugin at all.

#include <sourcemod>
#include <clientprefs>
#include <sdkhooks>
#include <sdktools>
#include <topmenus>
#include <dhooks>
#include <geoip>
#include <regex>

public void OnPluginStart()
{
    RegConsoleCmd("sm_try", OnPlayerCommandExecution, "sm_try - ...", FCVAR_GAMEDLL | FCVAR_UNLOGGED);
}

public Action OnPlayerCommandExecution(int nPlayer, int nArgs)
{
    static Handle xMenu;
    static Handle xStyle;

    if (nPlayer < 1)
    {
        return Plugin_Stop;
    }

    if (nPlayer > MaxClients)
    {
        return Plugin_Stop;
    }

    if (IsFakeClient(nPlayer))
    {
        return Plugin_Stop;
    }

    xStyle = GetMenuStyleHandle(MenuStyle_Radio);

    if (null == xStyle)
    {
        return Plugin_Stop;
    }

    xMenu = CreateMenuEx(xStyle, OnPlayerMenuExecution, MenuAction_Select | MenuAction_Cancel | MenuAction_End);

    if (null == xMenu)
    {
        CloseHandle(xStyle);

        return Plugin_Stop;
    }

    SetMenuTitle(xMenu, "YOUR ...");
    SetMenuPagination(xMenu, MENU_NO_PAGINATION);
    SetMenuExitButton(xMenu, false);
    SetMenuExitBackButton(xMenu, false);
    SetMenuNoVoteButton(xMenu, false);
    SetMenuOptionFlags(xMenu, MENUFLAG_NO_SOUND);

    AddMenuItem(xMenu, "...", "1...", ITEMDRAW_DEFAULT);
    AddMenuItem(xMenu, "...", "2...", ITEMDRAW_DEFAULT);
    AddMenuItem(xMenu, "...", "3...", ITEMDRAW_DEFAULT);
    AddMenuItem(xMenu, "...", "4...", ITEMDRAW_DEFAULT);
    AddMenuItem(xMenu, "...", "5...", ITEMDRAW_DEFAULT);
    AddMenuItem(xMenu, "...", "6...", ITEMDRAW_DEFAULT);
    AddMenuItem(xMenu, "...", "7...", ITEMDRAW_DEFAULT);
    AddMenuItem(xMenu, "...", "8...", ITEMDRAW_DEFAULT);

    AddMenuItem(xMenu, "", "", ITEMDRAW_SPACER);

    AddMenuItem(xMenu, "", "0...", ITEMDRAW_CONTROL);

    SetMenuTitle(xMenu, "YOUR ...");
    SetMenuPagination(xMenu, MENU_NO_PAGINATION);
    SetMenuExitButton(xMenu, false);
    SetMenuExitBackButton(xMenu, false);
    SetMenuNoVoteButton(xMenu, false);
    SetMenuOptionFlags(xMenu, MENUFLAG_NO_SOUND);

    DisplayMenu(xMenu, nPlayer, MENU_TIME_FOREVER);

    CloseHandle(xStyle);

    return Plugin_Stop;
}

public int OnPlayerMenuExecution(Handle xMenu, MenuAction xAction, int nThePrimaryParameter, int nTheSecondaryParameter)
{
    if (null == xMenu)
    {
        return 1;
    }

    if (MenuAction_Select == xAction)
    {
        // CloseHandle(xMenu); /// this will obviously throw an error log if uncommented

        return 1;
    }

    if (MenuAction_End == xAction)
    {
        CloseHandle(xMenu);

        return 1;
    }

    if (MenuAction_Cancel == xAction)
    {
        CloseHandle(xMenu);

        return 1;
    }

    CloseHandle(xMenu);

    return 1;
}
@ClaudiuHKS ClaudiuHKS changed the title CreateMenuEx, ..., DisplayMenu crash @ player disconnection CreateMenuEx, ..., DisplayMenu crash @ player disconnection # 1.12.0.7066 Nov 2, 2023
@ClaudiuHKS
Copy link
Author

ClaudiuHKS commented Nov 6, 2023

Update: How am I using the code above without getting any crashes or error logs?

  1. The menu handler -> No CloseHandle() at all.
  2. The CreateMenuEx() call -> After each CreateMenuEx() call, I add its Handle into an Array which elements are released during the OnMapStart() call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant