fix crash in wxDataViewItem GetNextItem() when there are no item.

Fixes #9540
https://gitlab.com/kicad/code/kicad/issues/9540
This commit is contained in:
jean-pierre charras 2021-11-07 08:53:56 +01:00
parent 97e9348ee1
commit 4293caf00c
1 changed files with 11 additions and 2 deletions

View File

@ -42,20 +42,29 @@ wxDataViewItem GetPrevItem( wxDataViewCtrl const& aView, wxDataViewItem const& a
wxDataViewItem GetNextItem( wxDataViewCtrl const& aView, wxDataViewItem const& aItem ) wxDataViewItem GetNextItem( wxDataViewCtrl const& aView, wxDataViewItem const& aItem )
{ {
wxDataViewItem nextItem; wxDataViewItem nextItem;
wxDataViewItem invalid;
if( !aItem.IsOk() ) if( !aItem.IsOk() )
{ {
// No selection. Select the first. // No selection. Select the first.
wxDataViewItemArray children; wxDataViewItemArray children;
aView.GetModel()->GetChildren( aItem, children ); aView.GetModel()->GetChildren( aItem, children );
return children[0];
if( children.size() )
return children[0];
return invalid;
} }
if( aView.IsExpanded( aItem ) ) if( aView.IsExpanded( aItem ) )
{ {
wxDataViewItemArray children; wxDataViewItemArray children;
aView.GetModel()->GetChildren( aItem, children ); aView.GetModel()->GetChildren( aItem, children );
nextItem = children[0];
if( children.size() )
return children[0];
return invalid;
} }
else else
{ {