Nullptr safety for UI Conditions.

We don't really control when these are called, so best not to assume
we've finished initialization of the frame/screen/document/whatever.

Possible fix for KICAD-KY.
This commit is contained in:
Jeff Young 2023-06-12 12:38:50 +01:00
parent aa8a903940
commit b7f0aae006
8 changed files with 74 additions and 71 deletions

View File

@ -628,19 +628,22 @@ void SCH_EDIT_FRAME::setupUIConditions()
auto belowRootSheetCondition =
[this]( const SELECTION& aSel )
{
return m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->CanGoUp();
SCH_NAVIGATE_TOOL* navigateTool = m_toolManager->GetTool<SCH_NAVIGATE_TOOL>();
return navigateTool && navigateTool->CanGoUp();
};
auto navSchematicHasPreviousSheet =
[this]( const SELECTION& aSel )
{
return m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->CanGoPrevious();
SCH_NAVIGATE_TOOL* navigateTool = m_toolManager->GetTool<SCH_NAVIGATE_TOOL>();
return navigateTool && navigateTool->CanGoPrevious();
};
auto navSchematicHasNextSheet =
[this]( const SELECTION& aSel )
{
return m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->CanGoNext();
SCH_NAVIGATE_TOOL* navigateTool = m_toolManager->GetTool<SCH_NAVIGATE_TOOL>();
return navigateTool && navigateTool->CanGoNext();
};
mgr->SetConditions( EE_ACTIONS::leaveSheet, ENABLE( belowRootSheetCondition ) );

View File

@ -389,7 +389,7 @@ void SYMBOL_EDIT_FRAME::setupUIConditions()
auto symbolModifiedCondition =
[this]( const SELECTION& sel )
{
return m_libMgr->IsSymbolModified( GetTargetLibId().GetLibItemName(),
return m_libMgr && m_libMgr->IsSymbolModified( GetTargetLibId().GetLibItemName(),
GetTargetLibId().GetLibNickname() );
};
@ -446,7 +446,7 @@ void SYMBOL_EDIT_FRAME::setupUIConditions()
auto pinTypeCond =
[this]( const SELECTION& )
{
return GetRenderSettings()->m_ShowPinsElectricalType;
return GetRenderSettings() && GetRenderSettings()->m_ShowPinsElectricalType;
};
auto showCompTreeCond =

View File

@ -420,20 +420,19 @@ void SYMBOL_VIEWER_FRAME::setupUIConditions()
auto electricalTypesShownCondition =
[this]( const SELECTION& aSel )
{
return GetRenderSettings()->m_ShowPinsElectricalType;
return GetRenderSettings() && GetRenderSettings()->m_ShowPinsElectricalType;
};
auto pinNumbersShownCondition =
[this]( const SELECTION& )
{
return GetRenderSettings()->m_ShowPinNumbers;
return GetRenderSettings() && GetRenderSettings()->m_ShowPinNumbers;
};
auto demorganCond =
[this]( const SELECTION& )
{
LIB_SYMBOL* symbol = GetSelectedSymbol();
return symbol && symbol->HasConversion();
};
@ -453,7 +452,6 @@ void SYMBOL_VIEWER_FRAME::setupUIConditions()
[this]( const SELECTION& )
{
LIB_SYMBOL* symbol = GetSelectedSymbol();
return symbol && !symbol->GetDatasheetField().GetText().IsEmpty();
};

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2013 CERN (www.cern.ch)
* Copyright (C) 2004-2022 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2004-2023 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License

View File

@ -1162,7 +1162,7 @@ void FOOTPRINT_EDIT_FRAME::setupUIConditions()
auto haveFootprintCond =
[this]( const SELECTION& )
{
return GetBoard()->GetFirstFootprint() != nullptr;
return GetBoard() && GetBoard()->GetFirstFootprint() != nullptr;
};
auto footprintTargettedCond =
@ -1221,7 +1221,7 @@ void FOOTPRINT_EDIT_FRAME::setupUIConditions()
auto boardFlippedCond =
[this]( const SELECTION& )
{
return GetCanvas()->GetView()->IsMirroredX();
return GetCanvas() && GetCanvas()->GetView()->IsMirroredX();
};
auto footprintTreeCond =
@ -1261,12 +1261,14 @@ void FOOTPRINT_EDIT_FRAME::setupUIConditions()
mgr->SetConditions( PCB_ACTIONS::repairFootprint, ENABLE( haveFootprintCond ) );
mgr->SetConditions( PCB_ACTIONS::cleanupGraphics, ENABLE( haveFootprintCond ) );
auto isArcKeepCenterMode = [this]( const SELECTION& )
auto isArcKeepCenterMode =
[this]( const SELECTION& )
{
return GetSettings()->m_ArcEditMode == ARC_EDIT_MODE::KEEP_CENTER_ADJUST_ANGLE_RADIUS;
};
auto isArcKeepEndpointMode = [this]( const SELECTION& )
auto isArcKeepEndpointMode =
[this]( const SELECTION& )
{
return GetSettings()->m_ArcEditMode == ARC_EDIT_MODE::KEEP_ENDPOINTS_OR_START_DIRECTION;
};
@ -1276,8 +1278,9 @@ void FOOTPRINT_EDIT_FRAME::setupUIConditions()
// Only enable a tool if the part is edtable
#define CURRENT_EDIT_TOOL( action ) mgr->SetConditions( action, \
ACTION_CONDITIONS().Enable( haveFootprintCond ).Check( cond.CurrentTool( action ) ) )
#define CURRENT_EDIT_TOOL( action ) \
mgr->SetConditions( action, ACTION_CONDITIONS().Enable( haveFootprintCond ) \
.Check( cond.CurrentTool( action ) ) )
CURRENT_EDIT_TOOL( ACTIONS::deleteTool );
CURRENT_EDIT_TOOL( ACTIONS::measureTool );

View File

@ -724,7 +724,7 @@ void PCB_EDIT_FRAME::setupUIConditions()
auto enableZoneControlCondition =
[this] ( const SELECTION& )
{
return GetBoard()->GetVisibleElements().Contains( LAYER_ZONES )
return GetBoard() && GetBoard()->GetVisibleElements().Contains( LAYER_ZONES )
&& GetDisplayOptions().m_ZoneOpacity > 0.0;
};
@ -752,16 +752,14 @@ void PCB_EDIT_FRAME::setupUIConditions()
auto enableBoardSetupCondition =
[this] ( const SELECTION& )
{
if( DRC_TOOL* tool = m_toolManager->GetTool<DRC_TOOL>() )
return !tool->IsDRCDialogShown();
return true;
DRC_TOOL* tool = m_toolManager->GetTool<DRC_TOOL>();
return !( tool && tool->IsDRCDialogShown() );
};
auto boardFlippedCond =
[this]( const SELECTION& )
{
return GetCanvas()->GetView()->IsMirroredX();
return GetCanvas() && GetCanvas()->GetView()->IsMirroredX();
};
auto layerManagerCond =
@ -811,7 +809,7 @@ void PCB_EDIT_FRAME::setupUIConditions()
[this]( const SELECTION& )
{
BOARD_INSPECTION_TOOL* tool = m_toolManager->GetTool<BOARD_INSPECTION_TOOL>();
return tool->IsNetHighlightSet();
return tool && tool->IsNetHighlightSet();
};
mgr->SetConditions( PCB_ACTIONS::toggleHV45Mode, CHECK( constrainedDrawingModeCond ) );
@ -826,15 +824,16 @@ void PCB_EDIT_FRAME::setupUIConditions()
mgr->SetConditions( PCB_ACTIONS::showProperties, CHECK( propertiesCond ) );
mgr->SetConditions( PCB_ACTIONS::showSearch, CHECK( searchPaneCond ) );
auto isArcKeepCenterMode = [this]( const SELECTION& )
auto isArcKeepCenterMode =
[this]( const SELECTION& )
{
return GetPcbNewSettings()->m_ArcEditMode == ARC_EDIT_MODE::KEEP_CENTER_ADJUST_ANGLE_RADIUS;
};
auto isArcKeepEndpointMode = [this]( const SELECTION& )
auto isArcKeepEndpointMode =
[this]( const SELECTION& )
{
return GetPcbNewSettings()->m_ArcEditMode
== ARC_EDIT_MODE::KEEP_ENDPOINTS_OR_START_DIRECTION;
return GetPcbNewSettings()->m_ArcEditMode == ARC_EDIT_MODE::KEEP_ENDPOINTS_OR_START_DIRECTION;
};
mgr->SetConditions( PCB_ACTIONS::pointEditorArcKeepCenter, CHECK( isArcKeepCenterMode ) );
@ -844,21 +843,21 @@ void PCB_EDIT_FRAME::setupUIConditions()
[this]( const SELECTION& )
{
ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
return tool->GetRouterMode() == PNS::RM_MarkObstacles;
return tool && tool->GetRouterMode() == PNS::RM_MarkObstacles;
};
auto isShoveMode =
[this]( const SELECTION& )
{
ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
return tool->GetRouterMode() == PNS::RM_Shove;
return tool && tool->GetRouterMode() == PNS::RM_Shove;
};
auto isWalkaroundMode =
[this]( const SELECTION& )
{
ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
return tool->GetRouterMode() == PNS::RM_Walkaround;
return tool && tool->GetRouterMode() == PNS::RM_Walkaround;
};
mgr->SetConditions( PCB_ACTIONS::routerHighlightMode, CHECK( isHighlightMode ) );
@ -925,7 +924,7 @@ void PCB_EDIT_FRAME::setupUIConditions()
[this] ( const SELECTION& )
{
DRC_TOOL* tool = m_toolManager->GetTool<DRC_TOOL>();
return !tool->IsDRCRunning();
return !( tool && tool->IsDRCRunning() );
};
#define CURRENT_EDIT_TOOL( action ) \