Don't try accessing library table rows that don't exist

When exiting the dialog without actually visiting the table, the grid
cursor could be missing, so it could return -1. Guard against that
condition.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/16342
This commit is contained in:
Ian McInerney 2023-12-11 23:36:51 +00:00
parent 11be5d6f1d
commit 53fd1aaf5e
1 changed files with 10 additions and 1 deletions

View File

@ -503,9 +503,18 @@ void GRID_CELL_PATH_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
void GRID_CELL_PATH_EDITOR::UpdateFilterString( const wxString& aFilterString )
{
if( m_fileFilterFn )
m_fileFilter = m_fileFilterFn( m_grid, m_grid->GetGridCursorRow() );
{
int row = m_grid->GetGridCursorRow();
// When closing the window, the cursor position could be negative if no rows were selected,
// so don't try to update a filter for a non-existent row
if( row >= 0 )
m_fileFilter = m_fileFilterFn( m_grid, row );
}
else
{
m_fileFilter = aFilterString;
}
// Ensure that the control switches between files and directories properly
TEXT_BUTTON_FILE_BROWSER* button = dynamic_cast<TEXT_BUTTON_FILE_BROWSER*>( m_control );