sourcemod
sourcemod copied to clipboard
TopMenuObject - plugin reload issue
Help us help you
- [x] I have checked that my issue doesn't exist yet.
- [x] I have tried my absolute best to reduce the problem-space and have provided the absolute smallest test-case possible.
- [x] I can always reproduce the issue with the provided description below.
Environment
- Operating System version: Windows 10 build 19044.1466
- Game/AppID (with version if applicable): 550 v2.2.2.3
- Current SourceMod version: 1.11.0.6853
- Current SourceMod snapshot: 1.11.0.6853
- Current Metamod: Source snapshot: 1.12.0-dev+1157
- [ ] I have updated SourceMod to the latest version and it still happens.
- [x] I have updated SourceMod to the latest snapshot and it still happens.
- [x] I have updated SourceMM to the latest snapshot and it still happens.
Description
Reloading plugin that adds items/category to admin menu will lead to crash or menu will be completely broken.
Method 1
- Type !admin
- Reload plugin with problematic code below (sm plugins unload X; sm plugins load N)
- Press 4
- Type !admin
- You will see broken menu (if you open admin menu you will always be in first category)
Method 2
- Type !admin
- Press 4
- Reload plugin with problematic code below (sm plugins unload X; sm plugins load N)
- Press back button
- Server crash
Problematic Code (or Steps to Reproduce)
Code
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <adminmenu>
#define ACTION_TITLE "Action Controller"
#define ADMIN_FLAG ADMFLAG_ROOT
TopMenu g_hTopMenu;
TopMenuObject g_hTopCategory;
public void OnPluginStart()
{
if ( LibraryExists("adminmenu") )
{
OnAdminMenuReady(GetAdminTopMenu());
}
}
public void OnLibraryRemoved( const char[] name )
{
if ( strcmp(name, "adminmenu") == 0 )
g_hTopMenu = null;
}
public void OnAdminMenuReady( Handle hTopMenu )
{
if ( hTopMenu == g_hTopMenu )
return;
g_hTopMenu = TopMenu.FromHandle(hTopMenu);
TopMenuObject category = g_hTopMenu.AddCategory("sub_behavior", ActionHandler, "behavior", ADMIN_FLAG);
if ( category == INVALID_TOPMENUOBJECT )
return;
g_hTopCategory = category;
g_hTopMenu.AddItem("123", ActionItemHandler, g_hTopCategory, "123", ADMIN_FLAG);
}
public void ActionHandler( TopMenu hMenu, TopMenuAction action, TopMenuObject objectID, int client, char[] buffer, int maxlength )
{
switch (action)
{
case TopMenuAction_DisplayOption, TopMenuAction_DisplayTitle: FormatEx(buffer, maxlength, ACTION_TITLE);
}
}
public void ActionItemHandler( TopMenu hMenu, TopMenuAction action, TopMenuObject objectID, int client, char[] buffer, int maxlength )
{
}
Logs
https://crash.limetech.org/yvcbilx7heuu https://crash.limetech.org/z2wkk55la7es https://crash.limetech.org/zkf7fsnlgdri
This looks like #1559 generally - but the result of "Method 1" might be the 1.11-specific weirdness mentioned in https://github.com/alliedmodders/sourcemod/issues/1473#issuecomment-951163010.