From a9544d0014003a3a1ea759b2a2d1c016b74959d6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 16 Oct 2010 18:11:32 +0000 Subject: [PATCH] Avoid crashes in wxGenericListCtrl client<->screen conversion code. At least in wxUniv build, DoScreenToClient() can be called before the main control window is created which results in a crash when attempting to forward to its DoScreenToClient() version. Check for m_mainWin being non-NULL before using it to at least avoid the crash, even if it's not really clear whether this is a 100% correct fix. Closes #12390. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65831 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/listctrl.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 1a82b85138..5a3ef5ac90 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -5061,12 +5061,22 @@ bool wxGenericListCtrl::DoPopupMenu( wxMenu *menu, int x, int y ) void wxGenericListCtrl::DoClientToScreen( int *x, int *y ) const { - m_mainWin->DoClientToScreen(x, y); + // It's not clear whether this can be called before m_mainWin is created + // but it seems better to be on the safe side and check. + if ( m_mainWin ) + m_mainWin->DoClientToScreen(x, y); + else + wxControl::DoClientToScreen(x, y); } void wxGenericListCtrl::DoScreenToClient( int *x, int *y ) const { - m_mainWin->DoScreenToClient(x, y); + // At least in wxGTK/Univ build this method can be called before m_mainWin + // is created so avoid crashes in this case. + if ( m_mainWin ) + m_mainWin->DoScreenToClient(x, y); + else + wxControl::DoScreenToClient(x, y); } void wxGenericListCtrl::SetFocus() -- 2.45.2