alliedmodders / sourcemod

SourceMod - Source Engine Scripting and Administration
http://www.sourcemod.net/
970 stars 423 forks source link

TopMenuObject - plugin reload issue #1710

Open Vinillia opened 2 years ago

Vinillia commented 2 years ago

Help us help you

Environment

Description

Reloading plugin that adds items/category to admin menu will lead to crash or menu will be completely broken.

Method 1

  1. Type !admin
  2. Reload plugin with problematic code below (sm plugins unload X; sm plugins load N)
  3. Press 4
  4. Type !admin
  5. You will see broken menu (if you open admin menu you will always be in first category)

Method 2

  1. Type !admin
  2. Press 4
  3. Reload plugin with problematic code below (sm plugins unload X; sm plugins load N)
  4. Press back button
  5. Server crash

Problematic Code (or Steps to Reproduce)

Code ``` #pragma semicolon 1 #pragma newdecls required #include #include #include #include #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

asherkin commented 2 years ago

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.