From 9c1e8fde8f80c1a37ea64d623944577d21d606d4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 13 Dec 2019 16:16:29 +0100 Subject: [PATCH] Avoid asserts when painting empty wxGridColLabelWindow When the grid is empty, XToCol() has no choice but to return invalid index (because there are no valid ones) when it's called from the drawing code and passing such indices to GetColPos() results in an assert, which is fatal inside wxEVT_PAINT handler. Just short-circuit all this code by not doing anything in the case of empty grid. This is sloppy, but simpler and more robust than any alternatives. Closes #18629. --- src/generic/grid.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index d4e82b5bd7..bff40831f1 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -1813,6 +1813,11 @@ void wxGridColLabelWindow::OnPaint( wxPaintEvent& WXUNUSED(event) ) // // m_owner->PrepareDC( dc ); + // Column indices become invalid when the grid is empty, so avoid doing + // anything at all in this case. + if ( m_owner->GetNumberCols() == 0 ) + return; + int x, y; wxGridWindow *gridWindow = IsFrozen() ? m_owner->m_frozenColGridWin : m_owner->m_gridWin;