diff --git a/common/rc_item.cpp b/common/rc_item.cpp index c655a34a5f..d333c8024b 100644 --- a/common/rc_item.cpp +++ b/common/rc_item.cpp @@ -55,11 +55,15 @@ wxString RC_ITEM::ShowReport( EDA_UNITS aUnits, const std::map& EDA_ITEM* mainItem = nullptr; EDA_ITEM* auxItem = nullptr; - if( m_mainItemUuid != niluuid ) - mainItem = aItemMap.at( m_mainItemUuid ); + auto ii = aItemMap.find( m_mainItemUuid ); - if( m_auxItemUuid != niluuid ) - auxItem = aItemMap.at( m_auxItemUuid ); + if( ii != aItemMap.end() ) + mainItem = ii->second; + + ii = aItemMap.find( m_auxItemUuid ); + + if( ii != aItemMap.end() ) + auxItem = ii->second; if( mainItem && auxItem ) { diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 7eec8b4f80..56456049a8 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -802,6 +802,9 @@ BOARD_ITEM* BOARD::GetItem( const KIID& aID ) void BOARD::FillItemMap( std::map& aMap ) { + // the board itself + aMap[ this->m_Uuid ] = this; + for( TRACK* track : Tracks() ) aMap[ track->m_Uuid ] = track; diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 3cdcc0bc0a..789fd2558f 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -392,6 +392,12 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : PCB_EDIT_FRAME::~PCB_EDIT_FRAME() { + // Close modeless dialogs + wxWindow* open_dlg = wxWindow::FindWindowByName( DIALOG_DRC_WINDOW_NAME ); + + if( open_dlg ) + open_dlg->Close( true ); + // Shutdown all running tools if( m_toolManager ) m_toolManager->ShutdownAllTools(); @@ -807,14 +813,6 @@ bool PCB_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent ) return false; } - // First close the DRC dialog. For some reason, if the board editor frame is destroyed - // when the DRC dialog currently open, Pcbnew crashes, at least on Windows. - DIALOG_DRC* open_dlg = static_cast( - wxWindow::FindWindowByName( DIALOG_DRC_WINDOW_NAME ) ); - - if( open_dlg ) - open_dlg->Close( true ); - if( IsContentModified() ) { wxFileName fileName = GetBoard()->GetFileName(); @@ -830,6 +828,13 @@ bool PCB_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent ) } } + // Close modeless dialogs. They're trouble when they get destroyed after the frame and/or + // board. + wxWindow* open_dlg = wxWindow::FindWindowByName( DIALOG_DRC_WINDOW_NAME ); + + if( open_dlg ) + open_dlg->Close( true ); + return true; }