Browse Source

Eeschema: fix crash when adding a new SCH_HIERLABEL.

The crash was due to use a temporary parent in SCH_LABEL_BASE::SetLabelShape()
The parent must be a SCH_SCREEN and is now tested before use.
It is also fixed and set to the current SCH_SCREEN at creation.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/21786
master
jean-pierre charras 2 weeks ago
parent
commit
96bf85977c
  1. 1
      common/eda_item.cpp
  2. 2
      eeschema/sch_label.cpp
  3. 6
      eeschema/tools/sch_drawing_tools.cpp

1
common/eda_item.cpp

@ -412,6 +412,7 @@ static struct EDA_ITEM_DESC
.Undefined( TYPE_NOT_INIT )
.Map( NOT_USED, wxT( "<not used>" ) )
.Map( SCREEN_T, _HKI( "Screen" ) )
.Map( SCHEMATIC_T, _HKI( "Schematic" ) )
.Map( PCB_FOOTPRINT_T, _HKI( "Footprint" ) )
.Map( PCB_PAD_T, _HKI( "Pad" ) )

2
eeschema/sch_label.cpp

@ -331,7 +331,7 @@ void SCH_LABEL_BASE::SetLabelShape( LABEL_SHAPE aShape )
if( Type() == SCH_HIER_LABEL_T )
{
SCH_HIERLABEL* label = static_cast<SCH_HIERLABEL*>( this );
SCH_SCREEN* screen = static_cast<SCH_SCREEN*>( label->GetParent() );
SCH_SCREEN* screen = dynamic_cast<SCH_SCREEN*>( label->GetParent() );
if( screen )
{

6
eeschema/tools/sch_drawing_tools.cpp

@ -1784,11 +1784,13 @@ bool SCH_DRAWING_TOOLS::createNewLabel( const VECTOR2I& aPosition, int aType,
break;
default:
wxFAIL_MSG( "SCH_EDIT_FRAME::CreateNewText() unknown layer type" );
wxFAIL_MSG( "SCH_DRAWING_TOOLS::createNewLabel() unknown label type" );
return false;
}
labelItem->SetParent( schematic );
// The normal parent is the current screen for these labels, set by SCH_SCREEN::Append()
// but it is also used during placement for SCH_HIERLABEL before beeing appended
labelItem->SetParent( m_frame->GetScreen() );
labelItem->SetTextSize( VECTOR2I( settings.m_DefaultTextSize, settings.m_DefaultTextSize ) );

Loading…
Cancel
Save