Fix crash when resetting wxGrid table with editor control shown

This resulted in a crash in GetDefaultEditorForCell() later when GetEditor()
was called from HideCellEditControl() which is itself always called from
wxGrid dtor because GetDefaultEditorForCell() dereferenced m_table without
checking if it was not null any more.

Add the missing check to this function and GetDefaultRendererForCell() too,
for consistency.

In addition, dismiss the cell editor immediately when changing table instead
of doing it at some later time, as it just doesn't make sense to continue
showing it any more as the data it was started to edit doesn't belong to us
any longer.
This commit is contained in:
Vadim Zeitlin 2016-06-22 01:11:20 +02:00
parent 4b98cd4012
commit ff5981230a

View File

@ -2322,6 +2322,17 @@ wxGrid::SetTable(wxGridTableBase *table,
if (m_table)
{
// We can't leave the in-place control editing the data of the
// table alive, as it would try to use the table object that we
// don't have any more later otherwise, so hide it manually.
//
// Notice that we can't call DisableCellEditControl() from here
// which would try to save the current editor value into the table
// which might be half-deleted by now, so we have to manually mark
// the edit control as being disabled.
HideCellEditControl();
m_cellEditCtrlEnabled = false;
m_table->SetView(0);
if( m_ownTable )
delete m_table;
@ -7933,12 +7944,18 @@ void wxGrid::RegisterDataType(const wxString& typeName,
wxGridCellEditor * wxGrid::GetDefaultEditorForCell(int row, int col) const
{
if ( !m_table )
return NULL;
wxString typeName = m_table->GetTypeName(row, col);
return GetDefaultEditorForType(typeName);
}
wxGridCellRenderer * wxGrid::GetDefaultRendererForCell(int row, int col) const
{
if ( !m_table )
return NULL;
wxString typeName = m_table->GetTypeName(row, col);
return GetDefaultRendererForType(typeName);
}