From be4162218d1d4cc7ea11ff4c0f7286c47086e3de Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Sep 2012 22:21:20 +0000 Subject: [PATCH] Don't crash in generic wxDataViewCtrl if it doesn't have any model. A model may be dissociated from a still existing control, don't crash if it happens (notice that we still would crash in the native GTK version right now, so this still remains to be fixed there). See #14616. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72590 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/datavgen.cpp | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 7fef06b83b..0317ea8144 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -2465,8 +2465,15 @@ bool wxDataViewMainWindow::Cleared() DestroyTree(); m_selection.Clear(); - SortPrepare(); - BuildTree( GetModel() ); + if (GetModel()) + { + SortPrepare(); + BuildTree( GetModel() ); + } + else + { + m_count = 0; + } GetOwner()->InvalidateColBestWidths(); UpdateDisplay(); @@ -4526,13 +4533,23 @@ bool wxDataViewCtrl::AssociateModel( wxDataViewModel *model ) if (!wxDataViewCtrlBase::AssociateModel( model )) return false; - m_notifier = new wxGenericDataViewModelNotifier( m_clientArea ); - - model->AddNotifier( m_notifier ); + if (model) + { + m_notifier = new wxGenericDataViewModelNotifier( m_clientArea ); + model->AddNotifier( m_notifier ); + } + else if (m_notifier) + { + m_notifier->Cleared(); + m_notifier = NULL; + } m_clientArea->DestroyTree(); - m_clientArea->BuildTree(model); + if (model) + { + m_clientArea->BuildTree(model); + } m_clientArea->UpdateDisplay(); -- 2.45.2