From 5992503b626c79290c3970e5cc18768608de79eb Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 1 Nov 2013 23:59:07 +0000 Subject: [PATCH] Reset current item in generic virtual wxListCtrl when items count changes. This ensures that we don't end up with an invalid current item value, which resulted in the asserts (see http://thread.gmane.org/gmane.comp.lib.wxwidgets.general/80341) and possibly worse. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@75118 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/listctrl.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 58a5c733eb..31c7478798 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -3496,6 +3496,12 @@ size_t wxListMainWindow::GetItemCount() const void wxListMainWindow::SetItemCount(long count) { + // Update the current item if it's not valid any longer (notice that this + // invalidates it completely if the control is becoming empty, which is the + // right thing to do). + if ( HasCurrent() && m_current >= (size_t)count ) + ChangeCurrent(count - 1); + m_selStore.SetItemCount(count); m_countVirt = count;