From 126563c839756009f6a8cfa3691c6a25e1133dc2 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 22 Nov 2021 11:47:17 -0800 Subject: [PATCH] Fix initilization project / ordering We cannot resolve the Canvas type without the canvas being initialized. But saving settings sometimes requests canvas access. This protects the calls against failure by checking for canvas before saving canvas-specific settings Fixes https://gitlab.com/kicad/code/kicad/issues/9729 --- eeschema/sch_base_frame.cpp | 16 ++++++++++++---- eeschema/symbol_viewer_frame.cpp | 4 +++- pcbnew/footprint_viewer_frame.cpp | 7 ++++--- pcbnew/pcb_edit_frame.cpp | 3 ++- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp index c8f5c80e97..c17dae875a 100644 --- a/eeschema/sch_base_frame.cpp +++ b/eeschema/sch_base_frame.cpp @@ -264,8 +264,11 @@ void SCH_BASE_FRAME::CenterScreen( const wxPoint& aCenterPoint, bool aWarpPointe void SCH_BASE_FRAME::HardRedraw() { - GetCanvas()->GetView()->UpdateAllItems( KIGFX::ALL ); - GetCanvas()->ForceRefresh(); + if( GetCanvas() && GetCanvas()->GetView() ) + { + GetCanvas()->GetView()->UpdateAllItems( KIGFX::ALL ); + GetCanvas()->ForceRefresh(); + } } @@ -277,8 +280,13 @@ SCH_DRAW_PANEL* SCH_BASE_FRAME::GetCanvas() const KIGFX::SCH_RENDER_SETTINGS* SCH_BASE_FRAME::GetRenderSettings() { - KIGFX::PAINTER* painter = GetCanvas()->GetView()->GetPainter(); - return static_cast( painter->GetSettings() ); + if( GetCanvas() && GetCanvas()->GetView() ) + { + if( KIGFX::PAINTER* painter = GetCanvas()->GetView()->GetPainter() ) + return static_cast( painter->GetSettings() ); + } + + return nullptr; } diff --git a/eeschema/symbol_viewer_frame.cpp b/eeschema/symbol_viewer_frame.cpp index b1f94fd759..6496a25ba7 100644 --- a/eeschema/symbol_viewer_frame.cpp +++ b/eeschema/symbol_viewer_frame.cpp @@ -722,7 +722,9 @@ void SYMBOL_VIEWER_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg) cfg->m_LibViewPanel.lib_list_width = m_libListWidth; cfg->m_LibViewPanel.cmp_list_width = m_symbolListWidth; - cfg->m_LibViewPanel.show_pin_electrical_type = GetRenderSettings()->m_ShowPinsElectricalType; + + if( GetRenderSettings() ) + cfg->m_LibViewPanel.show_pin_electrical_type = GetRenderSettings()->m_ShowPinsElectricalType; } diff --git a/pcbnew/footprint_viewer_frame.cpp b/pcbnew/footprint_viewer_frame.cpp index ac367510f1..ddd064350c 100644 --- a/pcbnew/footprint_viewer_frame.cpp +++ b/pcbnew/footprint_viewer_frame.cpp @@ -178,14 +178,14 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent fpPanel->Fit(); // Create GAL canvas - resolveCanvasType(); m_canvasType = loadCanvasTypeSetting(); - SwitchCanvas( m_canvasType ); PCB_DRAW_PANEL_GAL* drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_frameSize, GetGalDisplayOptions(), m_canvasType ); SetCanvas( drawPanel ); + resolveCanvasType(); + SetBoard( new BOARD() ); // This board will only be used to hold a footprint for viewing @@ -794,7 +794,8 @@ void FOOTPRINT_VIEWER_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) // We don't want to store anything other than the window settings PCB_BASE_FRAME::SaveSettings( cfg ); - cfg->m_FootprintViewerZoom = GetCanvas()->GetView()->GetScale(); + if( GetCanvas() && GetCanvas()->GetView() ) + cfg->m_FootprintViewerZoom = GetCanvas()->GetView()->GetScale(); } diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index b36ce218ae..6545b5a1ad 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -990,7 +990,8 @@ void PCB_EDIT_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) cfg->m_ShowPageLimits = m_showPageLimits; } - GetSettingsManager()->SaveColorSettings( GetColorSettings(), "board" ); + if( GetSettingsManager() ) + GetSettingsManager()->SaveColorSettings( GetColorSettings(), "board" ); }