From 7b375bd7cede6fb4bffbb813d49ac4f180b779e9 Mon Sep 17 00:00:00 2001 From: "seer-by-sentry[bot]" <157164994+seer-by-sentry[bot]@users.noreply.github.com> Date: Fri, 30 Jan 2026 12:36:49 +0000 Subject: [PATCH] Fix state machine destructor access violation --- Generals/Code/GameEngine/Source/Common/StateMachine.cpp | 9 ++++++--- .../Code/GameEngine/Source/Common/StateMachine.cpp | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Generals/Code/GameEngine/Source/Common/StateMachine.cpp b/Generals/Code/GameEngine/Source/Common/StateMachine.cpp index bd78f0a888..cfc53d7188 100644 --- a/Generals/Code/GameEngine/Source/Common/StateMachine.cpp +++ b/Generals/Code/GameEngine/Source/Common/StateMachine.cpp @@ -283,9 +283,12 @@ StateMachine::StateMachine( Object *owner, AsciiString name ) StateMachine::~StateMachine() { - // do not allow current state to exit - if (m_currentState) - m_currentState->onExit( EXIT_RESET ); + // TheSuperHackers @bugfix 30/01/2025 Do not call onExit() on m_currentState during destruction. + // The state may already be in an invalid state or point to deleted memory during object destruction, + // especially when objects are being destroyed in GameLogic::processDestroyList. + // The halt() method already clears m_currentState in AIUpdateInterface::~AIUpdateInterface before + // the state machine is deleted, so this call is unnecessary and can cause access violations. + // See: https://sentry.io/share/issue/[issue-id]/ std::map::iterator i; diff --git a/GeneralsMD/Code/GameEngine/Source/Common/StateMachine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/StateMachine.cpp index 8e7612cade..5fbfb04ff1 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/StateMachine.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/StateMachine.cpp @@ -283,9 +283,12 @@ StateMachine::StateMachine( Object *owner, AsciiString name ) StateMachine::~StateMachine() { - // do not allow current state to exit - if (m_currentState) - m_currentState->onExit( EXIT_RESET ); + // TheSuperHackers @bugfix 30/01/2025 Do not call onExit() on m_currentState during destruction. + // The state may already be in an invalid state or point to deleted memory during object destruction, + // especially when objects are being destroyed in GameLogic::processDestroyList. + // The halt() method already clears m_currentState in AIUpdateInterface::~AIUpdateInterface before + // the state machine is deleted, so this call is unnecessary and can cause access violations. + // See: https://sentry.io/share/issue/[issue-id]/ std::map::iterator i;