Attempt to fix crash on exit

The update check runs on the thread pool and captures a raw pointer to the
KICAD_MANAGER_FRAME for CallAfter. If the update check completes during
frame destruction, the CallAfter targets a partially-destroyed window,
causing a segfault in wxWindowBase::RemoveEventHandler via wxAuiNotebook
destruction.  At least, that is the theory...

Fixes https://gitlab.com/kicad/code/kicad/-/issues/22593

(cherry picked from commit c0230e74c1)
This commit is contained in:
Seth Hillbrand
2026-02-23 18:05:43 -08:00
parent d911483455
commit 78c0d81eb0
2 changed files with 13 additions and 2 deletions
+8
View File
@@ -314,6 +314,11 @@ KICAD_MANAGER_FRAME::~KICAD_MANAGER_FRAME()
if( m_pcm )
m_pcm->StopBackgroundUpdate();
// Stop update manager before tearing down the AUI framework. The update
// task runs on the thread pool and may call CallAfter on this frame, so it
// must complete before we uninitialize AUI or destroy child windows.
m_updateManager.reset();
delete m_actions;
delete m_toolManager;
delete m_toolDispatcher;
@@ -378,6 +383,9 @@ void KICAD_MANAGER_FRAME::CreatePCM()
m_pcm = std::make_shared<PLUGIN_CONTENT_MANAGER>(
[this]( int aUpdateCount )
{
if( Pgm().m_Quitting )
return;
m_pcmUpdateCount = aUpdateCount;
if( aUpdateCount > 0 )
+5 -2
View File
@@ -229,7 +229,7 @@ void UPDATE_MANAGER::CheckForUpdate( wxWindow* aNoticeParent )
// Check that the response is 200 (content provided)
// We can also return 204 for no update
if( responseCode == 200 )
if( responseCode == 200 && !Pgm().m_Quitting )
{
nlohmann::json update_json;
UPDATE_RESPONSE response;
@@ -239,11 +239,14 @@ void UPDATE_MANAGER::CheckForUpdate( wxWindow* aNoticeParent )
update_json_stream >> update_json;
response = update_json.get<UPDATE_RESPONSE>();
if( response.version != settings->m_lastReceivedUpdate )
if( response.version != settings->m_lastReceivedUpdate && !Pgm().m_Quitting )
{
aNoticeParent->CallAfter(
[aNoticeParent, response]()
{
if( Pgm().m_Quitting )
return;
auto notice = new DIALOG_UPDATE_NOTICE( aNoticeParent,
response.version,
response.details_url,