From 2531780c3bbda4717aa7e2ec7ce3fa01f813582f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 18 Mar 2019 18:18:47 +0100 Subject: [PATCH] Avoid division by 0 in generic wxDataViewCtrl scrolling code Apparently, ScrollTo() can be called when processing keyboard input in the control before its initial resize and hence before scrolling is initialized and in this case per-unit scroll units are still 0, so dividing by them is not a good idea. Just avoid scrolling in this case. Closes https://github.com/wxWidgets/wxWidgets/pull/1262 --- src/generic/datavgen.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index d398cc1c5a..3883a51c07 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -3110,9 +3110,12 @@ void wxDataViewMainWindow::ScrollTo( int rows, int column ) int x, y; m_owner->GetScrollPixelsPerUnit( &x, &y ); - int sy = GetLineStart( rows )/y; + + // Take care to not divide by 0 if we're somehow called before scrolling + // parameters are initialized. + int sy = y ? GetLineStart( rows )/y : -1; int sx = -1; - if( column != -1 ) + if( column != -1 && x ) { wxRect rect = GetClientRect(); int colnum = 0;