diff --git a/Generals/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetListBox.cpp b/Generals/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetListBox.cpp index a2b8bc5f3f7..c99169f371e 100644 --- a/Generals/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetListBox.cpp +++ b/Generals/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetListBox.cpp @@ -258,6 +258,11 @@ static void adjustDisplay( GameWindow *window, Int adjustment, GameWindow *child; sData = (SliderData *)list->slider->winGetUserData(); + + // Safety check: ensure slider data is valid before accessing it + if( sData == NULL ) + return; + list->slider->winGetSize( &sliderSize.x, &sliderSize.y ); // Take into account that there is a line-drawn outline surrounding listbox sData->maxVal = list->totalHeight - ( list->displayHeight - TOTAL_OUTLINE_HEIGHT ) + 1; @@ -1973,6 +1978,11 @@ WindowMsgHandledType GadgetListBoxSystem( GameWindow *window, UnsignedInt msg, if( list->multiSelect ) delete[]( list->selections ); + // Clear child window pointers to prevent dangling pointer access + list->slider = NULL; + list->upButton = NULL; + list->downButton = NULL; + delete (ListboxData *)window->winGetUserData(); window->winSetUserData( NULL ); list = NULL; diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetListBox.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetListBox.cpp index d906b74d8b9..fa78119806d 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetListBox.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetListBox.cpp @@ -258,6 +258,11 @@ static void adjustDisplay( GameWindow *window, Int adjustment, GameWindow *child; sData = (SliderData *)list->slider->winGetUserData(); + + // Safety check: ensure slider data is valid before accessing it + if( sData == NULL ) + return; + list->slider->winGetSize( &sliderSize.x, &sliderSize.y ); // Take into account that there is a line-drawn outline surrounding listbox sData->maxVal = list->totalHeight - ( list->displayHeight - TOTAL_OUTLINE_HEIGHT ) + 1; @@ -1973,6 +1978,11 @@ WindowMsgHandledType GadgetListBoxSystem( GameWindow *window, UnsignedInt msg, if( list->multiSelect ) delete[]( list->selections ); + // Clear child window pointers to prevent dangling pointer access + list->slider = NULL; + list->upButton = NULL; + list->downButton = NULL; + delete (ListboxData *)window->winGetUserData(); window->winSetUserData( NULL ); list = NULL;