Skip to content
Permalink
Browse files

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.
  • Loading branch information...
vadz committed Jun 21, 2016
1 parent 4b98cd4 commit ff5981230a1adc46c4ab3d895e2ff5d0c4cf96f0
Showing with 17 additions and 0 deletions.
  1. +17 −0 src/generic/grid.cpp
@@ -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);
}

0 comments on commit ff59812

Please sign in to comment.
You can’t perform that action at this time.