diff --git a/core/debuggercontroller.cpp b/core/debuggercontroller.cpp index 1713fe19..66544587 100644 --- a/core/debuggercontroller.cpp +++ b/core/debuggercontroller.cpp @@ -1875,8 +1875,18 @@ void DebuggerController::EventHandler(const DebuggerEvent& event) if (m_accessor) { - delete m_accessor; + // Defer deletion to a detached thread. The accessor holds a DbgRef, + // and if it is the last reference, deleting it here (on the event thread) would trigger + // ~DebuggerController which calls m_debuggerEventThread.join() -- deadlocking/crashing + // because we ARE the event thread. + // + // This can happen when Destroy() races with event processing: EventHandler sets + // ConnectionStatus to NotConnected (line above), and another thread observes this, + // calls Destroy() which removes the global array ref, making the accessor's DbgRef + // the last reference to the controller. + auto* accessor = m_accessor; m_accessor = nullptr; + std::thread([accessor]() { delete accessor; }).detach(); } m_lastIP = m_currentIP; m_currentIP = 0;