Protect the Kiway dereference

Also find a few more places where we are reaching into a new frame to
perform actions that need to have dialogs closed.

Running actions should also wait for the next cycle rather than being
immediately executed when we are calling into a new frame.  This allow
for the cleanup actions onClose() to happen prior to the next action
starting

Fixes https://gitlab.com/kicad/code/kicad/issues/11891

(cherry picked from commit 93fb00d815)
This commit is contained in:
Seth Hillbrand 2022-07-14 11:36:07 -07:00
parent 995b2c517d
commit c1ec63d4f9
6 changed files with 40 additions and 4 deletions

View File

@ -123,7 +123,8 @@ DIALOG_SHIM::DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& titl
if( kiwayHolder )
SetKiway( this, &kiwayHolder->Kiway() );
Kiway().SetBlockingDialog( this );
if( HasKiway() )
Kiway().SetBlockingDialog( this );
Bind( wxEVT_CLOSE_WINDOW, &DIALOG_SHIM::OnCloseWindow, this );
Bind( wxEVT_BUTTON, &DIALOG_SHIM::OnButton, this );
@ -146,7 +147,8 @@ DIALOG_SHIM::~DIALOG_SHIM()
if( IsQuasiModal() )
EndQuasiModal( wxID_CANCEL );
Kiway().SetBlockingDialog( nullptr );
if( HasKiway() )
Kiway().SetBlockingDialog( nullptr );
if( m_qmodal_parent_disabler )
delete m_qmodal_parent_disabler; // usually NULL by now

View File

@ -1528,6 +1528,11 @@ void SIM_PLOT_FRAME::onProbe( wxCommandEvent& event )
if( m_schematicFrame == nullptr )
return;
wxWindow* blocking_dialog = m_schematicFrame->Kiway().GetBlockingDialog();
if( blocking_dialog )
blocking_dialog->Close( true );
m_schematicFrame->GetToolManager()->RunAction( EE_ACTIONS::simProbe );
m_schematicFrame->Raise();
}
@ -1540,6 +1545,11 @@ void SIM_PLOT_FRAME::onTune( wxCommandEvent& event )
if( m_schematicFrame == nullptr )
return;
wxWindow* blocking_dialog = m_schematicFrame->Kiway().GetBlockingDialog();
if( blocking_dialog )
blocking_dialog->Close( true );
m_schematicFrame->GetToolManager()->RunAction( EE_ACTIONS::simTune );
m_schematicFrame->Raise();
}

View File

@ -534,7 +534,7 @@ int SYMBOL_EDITOR_CONTROL::AddSymbolToSchematic( const TOOL_EVENT& aEvent )
symbol->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false );
schframe->Raise();
schframe->GetToolManager()->RunAction( EE_ACTIONS::placeSymbol, true, symbol );
schframe->GetToolManager()->RunAction( EE_ACTIONS::placeSymbol, false, symbol );
}
return 0;

View File

@ -56,6 +56,15 @@ public:
return *m_kiway;
}
/**
* Safety check before asking for the Kiway reference
* @return true if kiway is non-null
*/
bool HasKiway() const
{
return m_kiway != nullptr;
}
/**
* Return a reference to the #PROJECT associated with this #KIWAY.
*/

View File

@ -183,6 +183,11 @@ void KICAD_MANAGER_FRAME::ImportNonKiCadProject( const wxString& aWindowTitle,
{
KIWAY_PLAYER* schframe = Kiway().Player( FRAME_SCH, true );
wxWindow* blocking_dialog = schframe->Kiway().GetBlockingDialog();
if( blocking_dialog )
blocking_dialog->Close( true );
packet = StrPrintf( "%d\n%s", aSchFileType, TO_UTF8( schCopy.GetFullPath() ) );
schframe->Kiway().ExpressMail( FRAME_SCH, MAIL_IMPORT_FILE, packet, this );
@ -203,6 +208,11 @@ void KICAD_MANAGER_FRAME::ImportNonKiCadProject( const wxString& aWindowTitle,
{
KIWAY_PLAYER* pcbframe = Kiway().Player( FRAME_PCB_EDITOR, true );
wxWindow* blocking_dialog = pcbframe->Kiway().GetBlockingDialog();
if( blocking_dialog )
blocking_dialog->Close( true );
if( !pcbframe->IsVisible() )
pcbframe->Show( true );

View File

@ -732,6 +732,11 @@ void FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB( wxCommandEvent& aEvent )
return;
}
wxWindow* blocking_dialog = pcbframe->Kiway().GetBlockingDialog();
if( blocking_dialog )
blocking_dialog->Close( true );
toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
BOARD_COMMIT commit( pcbframe );
@ -768,7 +773,7 @@ void FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB( wxCommandEvent& aEvent )
commit.Push( wxT( "Insert footprint" ) );
pcbframe->Raise();
toolMgr->RunAction( PCB_ACTIONS::placeFootprint, true, newFootprint );
toolMgr->RunAction( PCB_ACTIONS::placeFootprint, false, newFootprint );
newFootprint->ClearFlags();
}