]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't crash in generic wxDataViewCtrl if it doesn't have any model.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 30 Sep 2012 22:21:20 +0000 (22:21 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 30 Sep 2012 22:21:20 +0000 (22:21 +0000)
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

index 7fef06b83bfdfaaa1c5eb3d1a1d4d5c8105f7d1d..0317ea81445be9fb200a4b470cb46b81d48c4a22 100644 (file)
@@ -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();