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
This commit is contained in:
Seth Hillbrand 2021-11-22 11:47:17 -08:00
parent 5060c73625
commit 126563c839
4 changed files with 21 additions and 9 deletions

View File

@ -264,8 +264,11 @@ void SCH_BASE_FRAME::CenterScreen( const wxPoint& aCenterPoint, bool aWarpPointe
void SCH_BASE_FRAME::HardRedraw() void SCH_BASE_FRAME::HardRedraw()
{ {
GetCanvas()->GetView()->UpdateAllItems( KIGFX::ALL ); if( GetCanvas() && GetCanvas()->GetView() )
GetCanvas()->ForceRefresh(); {
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::SCH_RENDER_SETTINGS* SCH_BASE_FRAME::GetRenderSettings()
{ {
KIGFX::PAINTER* painter = GetCanvas()->GetView()->GetPainter(); if( GetCanvas() && GetCanvas()->GetView() )
return static_cast<KIGFX::SCH_RENDER_SETTINGS*>( painter->GetSettings() ); {
if( KIGFX::PAINTER* painter = GetCanvas()->GetView()->GetPainter() )
return static_cast<KIGFX::SCH_RENDER_SETTINGS*>( painter->GetSettings() );
}
return nullptr;
} }

View File

@ -722,7 +722,9 @@ void SYMBOL_VIEWER_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg)
cfg->m_LibViewPanel.lib_list_width = m_libListWidth; cfg->m_LibViewPanel.lib_list_width = m_libListWidth;
cfg->m_LibViewPanel.cmp_list_width = m_symbolListWidth; 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;
} }

View File

@ -178,14 +178,14 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent
fpPanel->Fit(); fpPanel->Fit();
// Create GAL canvas // Create GAL canvas
resolveCanvasType();
m_canvasType = loadCanvasTypeSetting(); m_canvasType = loadCanvasTypeSetting();
SwitchCanvas( m_canvasType );
PCB_DRAW_PANEL_GAL* drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_frameSize, PCB_DRAW_PANEL_GAL* drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_frameSize,
GetGalDisplayOptions(), m_canvasType ); GetGalDisplayOptions(), m_canvasType );
SetCanvas( drawPanel ); SetCanvas( drawPanel );
resolveCanvasType();
SetBoard( new BOARD() ); SetBoard( new BOARD() );
// This board will only be used to hold a footprint for viewing // 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 // We don't want to store anything other than the window settings
PCB_BASE_FRAME::SaveSettings( cfg ); PCB_BASE_FRAME::SaveSettings( cfg );
cfg->m_FootprintViewerZoom = GetCanvas()->GetView()->GetScale(); if( GetCanvas() && GetCanvas()->GetView() )
cfg->m_FootprintViewerZoom = GetCanvas()->GetView()->GetScale();
} }

View File

@ -990,7 +990,8 @@ void PCB_EDIT_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
cfg->m_ShowPageLimits = m_showPageLimits; cfg->m_ShowPageLimits = m_showPageLimits;
} }
GetSettingsManager()->SaveColorSettings( GetColorSettings(), "board" ); if( GetSettingsManager() )
GetSettingsManager()->SaveColorSettings( GetColorSettings(), "board" );
} }