diff view/PaneStack.cpp @ 729:25b3d5802e6e

Fix failure to delete property stack when pane is deleted (sometimes)
author Chris Cannam
date Tue, 04 Mar 2014 15:32:28 +0000
parents 1a0dfcbffaf1
children b6dc57688c72
line wrap: on
line diff
--- a/view/PaneStack.cpp	Thu Feb 06 18:34:43 2014 +0000
+++ b/view/PaneStack.cpp	Tue Mar 04 15:32:28 2014 +0000
@@ -236,11 +236,16 @@
 void
 PaneStack::deletePane(Pane *pane)
 {
+    cerr << "PaneStack::deletePane(" << pane << ")" << endl;
+
     std::vector<PaneRec>::iterator i;
     bool found = false;
 
+    QWidget *stack = 0;
+
     for (i = m_panes.begin(); i != m_panes.end(); ++i) {
 	if (i->pane == pane) {
+            stack = i->propertyStack;
 	    m_panes.erase(i);
 	    found = true;
 	    break;
@@ -251,6 +256,7 @@
 
 	for (i = m_hiddenPanes.begin(); i != m_hiddenPanes.end(); ++i) {
 	    if (i->pane == pane) {
+                stack = i->propertyStack;
 		m_hiddenPanes.erase(i);
 		found = true;
 		break;
@@ -265,6 +271,18 @@
 
     emit paneAboutToBeDeleted(pane);
 
+    cerr << "PaneStack::deletePane: about to delete parent " << pane->parent() << " of pane " << pane << endl;
+
+    // The property stack associated with the parent was initially
+    // created with the same parent as it, so it would be deleted when
+    // we delete the pane's parent in a moment -- but it may have been
+    // reparented depending on the layout. We'd better delete it
+    // separately first. (This fixes a crash on opening a new layer
+    // with a new unit type in it, when a long-defunct property box
+    // could be signalled from the unit database to tell it that a new
+    // unit had appeared.)
+    delete stack;
+
     delete pane->parent();
 
     if (m_currentPane == pane) {