From d8b45274cd67177427f3480f2ce4e9345d83612f Mon Sep 17 00:00:00 2001 From: dsarrut Date: Thu, 7 Apr 2011 08:51:20 +0000 Subject: [PATCH] Romulo - Solved bug 295 + Removed the "destroyed" flag + List/Tree widget is now cleared in the destructor + Destruction order was the cause for the crash - Made destructors virtual in the base classes + It could contribute to memory leaks + Other class hierarchies should be checked as well --- vv/vvToolBase.h | 2 ++ vv/vvToolBaseBase.h | 3 +++ vv/vvToolStructureSetManager.cxx | 26 +++++++++++--------------- vv/vvToolStructureSetManager.h | 3 +-- vv/vvToolWidgetBase.h | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/vv/vvToolBase.h b/vv/vvToolBase.h index 2abd2a6..b4a6cd8 100644 --- a/vv/vvToolBase.h +++ b/vv/vvToolBase.h @@ -27,6 +27,8 @@ template class vvToolBase : public vvToolBaseBase { public: vvToolBase(vvMainWindowBase * m); + virtual ~vvToolBase() {}; + static void Initialize(); // can't be virtual, must be overwritten static void SetToolName(QString n) { vvToolCreator::GetInstance()->mToolName = n; } diff --git a/vv/vvToolBaseBase.h b/vv/vvToolBaseBase.h index 74cd25b..ffd169b 100644 --- a/vv/vvToolBaseBase.h +++ b/vv/vvToolBaseBase.h @@ -23,6 +23,9 @@ //------------------------------------------------------------------------------ class vvToolBaseBase { +public: + virtual ~vvToolBaseBase() {}; + protected: vvMainWindowBase * mMainWindowBase; }; diff --git a/vv/vvToolStructureSetManager.cxx b/vv/vvToolStructureSetManager.cxx index c9e3368..fd09b11 100644 --- a/vv/vvToolStructureSetManager.cxx +++ b/vv/vvToolStructureSetManager.cxx @@ -27,7 +27,8 @@ #include #include #include - +#include + // vtk #include #include @@ -41,7 +42,6 @@ ADD_TOOL(vvToolStructureSetManager); int vvToolStructureSetManager::m_NumberOfTool = 0; std::vector vvToolStructureSetManager::mListOfInputs; std::map vvToolStructureSetManager::mListOfOpenTool; -bool vvToolStructureSetManager::mDestroyed = false; //------------------------------------------------------------------------------ vvToolStructureSetManager::vvToolStructureSetManager(vvMainWindowBase * parent, @@ -100,9 +100,15 @@ vvToolStructureSetManager::vvToolStructureSetManager(vvMainWindowBase * parent, //------------------------------------------------------------------------------ vvToolStructureSetManager::~vvToolStructureSetManager() { - //std::cout << "vvToolStructureSetManager::~vvToolStructureSetManager()" << std::endl; m_NumberOfTool--; - mDestroyed=true; + + // clearing the list at this point avoids + // segfaulting due to events being dispatched + // after object destruction + mTreeWidgetList.clear(); + mTree->clearSelection(); + + //std::cout << "vvToolStructureSetManager::~vvToolStructureSetManager()" << std::endl; } //------------------------------------------------------------------------------ @@ -362,6 +368,7 @@ void vvToolStructureSetManager::apply() bool vvToolStructureSetManager::close() { //std::cout << "vvToolStructureSetManager::close()" << std::endl; + return vvToolWidgetBase::close(); } //------------------------------------------------------------------------------ @@ -371,7 +378,6 @@ bool vvToolStructureSetManager::close() void vvToolStructureSetManager::closeEvent(QCloseEvent *event) { //std::cout << "vvToolStructureSetManager::closeEvent()" << std::endl; - disconnect(mTree, SIGNAL(itemSelectionChanged())); std::vector::iterator iter = std::find(mListOfInputs.begin(), mListOfInputs.end(), mCurrentSlicerManager); if (iter != mListOfInputs.end()) mListOfInputs.erase(iter); @@ -403,16 +409,6 @@ void vvToolStructureSetManager::closeEvent(QCloseEvent *event) //------------------------------------------------------------------------------ void vvToolStructureSetManager::SelectedItemChangedInTree() { - // ATTENTION: - // RP - 05/04/2011 - // Horrible solution for the problem of triggering this event - // after the window has been closed and the object instance - // has been destroyed. I couldn't find the place where the - // window is destroyed, though. - // - if (mDestroyed) - return; - // Search which roi is selected QList l = mTree->selectedItems(); if (l.size() == 0) { diff --git a/vv/vvToolStructureSetManager.h b/vv/vvToolStructureSetManager.h index 89af5ab..5bbc715 100644 --- a/vv/vvToolStructureSetManager.h +++ b/vv/vvToolStructureSetManager.h @@ -39,7 +39,7 @@ class vvToolStructureSetManager: Q_OBJECT public: vvToolStructureSetManager(vvMainWindowBase* parent=0, Qt::WindowFlags f=0, vvSlicerManager * c = NULL); - ~vvToolStructureSetManager(); + virtual ~vvToolStructureSetManager(); static void Initialize(); virtual void InputIsSelected(vvSlicerManager *m); @@ -95,7 +95,6 @@ protected: virtual void CheckInputList(std::vector & l, int & index); static std::vector mListOfInputs; static std::map mListOfOpenTool; - static bool mDestroyed; static int m_NumberOfTool; bool MustOpenDialogWhenCreated; diff --git a/vv/vvToolWidgetBase.h b/vv/vvToolWidgetBase.h index 0951fa1..2c3ddd9 100644 --- a/vv/vvToolWidgetBase.h +++ b/vv/vvToolWidgetBase.h @@ -37,7 +37,7 @@ class vvToolWidgetBase: public: vvToolWidgetBase(vvMainWindowBase * parent=0, Qt::WindowFlags f=Qt::Dialog, bool initialize=true); // default is a dialog - ~vvToolWidgetBase(); + virtual ~vvToolWidgetBase(); virtual void InputIsSelected(vvSlicerManager *m); virtual void InputIsSelected(std::vector & l); -- 2.47.1