Salome HOME
Fix bug 12109: SIGSEGV after trying to create sub-mesh in the second study.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_SelectionOp.cxx
index c03de45c1dfb03c362c3587681e23948778c55bd..2616fa69f7a6f8b6636dddb83be18140808cd5d9 100644 (file)
@@ -67,11 +67,7 @@ SMESHGUI_SelectionOp::SMESHGUI_SelectionOp( const Selection_Mode mode )
 //=================================================================================
 SMESHGUI_SelectionOp::~SMESHGUI_SelectionOp()
 {
-  Filters::const_iterator anIt = myFilters.begin(),
-                          aLast = myFilters.end();
-  for( ; anIt!=aLast; anIt++ )
-    if( anIt.data() )
-      delete anIt.data();
+  removeCustomFilters();
 }
 
 //=================================================================================
@@ -99,17 +95,21 @@ void SMESHGUI_SelectionOp::startOperation()
 // name     : removeCustomFilters
 // purpose  :
 //=================================================================================
-void SMESHGUI_SelectionOp::removeCustomFilters() const
+void SMESHGUI_SelectionOp::removeCustomFilters()
 {
-  LightApp_SelectionMgr* mgr = selectionMgr();
-  if( !mgr )
-    return;
-    
-  Filters::const_iterator anIt = myFilters.begin(),
-                          aLast = myFilters.end();
-  for( ; anIt!=aLast; anIt++ )
-    if( anIt.data() )
-      mgr->removeFilter( anIt.data() );
+  if (myFilters.count() > 0) {
+    LightApp_SelectionMgr* mgr = selectionMgr();
+    Filters::const_iterator anIt = myFilters.begin(),
+                            aLast = myFilters.end();
+    for (; anIt != aLast; anIt++) {
+      if (anIt.data()) {
+        if (mgr) mgr->removeFilter(anIt.data());
+        delete anIt.data();
+      }
+    }
+
+    myFilters.clear();
+  }
 }
 
 //=================================================================================
@@ -195,9 +195,7 @@ void SMESHGUI_SelectionOp::onActivateObject( int id )
 //=================================================================================
 void SMESHGUI_SelectionOp::onDeactivateObject( int id )
 {
-  LightApp_SelectionMgr* mgr = selectionMgr();
-  if( mgr && myFilters.contains( id ) && myFilters[ id ] )
-    mgr->removeFilter( myFilters[ id ] );
+  removeCustomFilters();
 }
 
 //=================================================================================