From 5ff23c37480e123709a798385dae829736d10f05 Mon Sep 17 00:00:00 2001 From: ouv Date: Thu, 3 Sep 2009 08:50:15 +0000 Subject: [PATCH] To avoid memory leaks --- src/OBJECT/SMESH_PreviewActorsCollection.cxx | 40 ++++++++++--------- .../StdMeshersGUI_SubShapeSelectorWdg.cxx | 25 +++++++++--- 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/src/OBJECT/SMESH_PreviewActorsCollection.cxx b/src/OBJECT/SMESH_PreviewActorsCollection.cxx index 59238dcf1..d07e33b71 100644 --- a/src/OBJECT/SMESH_PreviewActorsCollection.cxx +++ b/src/OBJECT/SMESH_PreviewActorsCollection.cxx @@ -78,6 +78,10 @@ SMESH_PreviewActorsCollection if (myRenderer) RemoveFromRender(myRenderer); + QMap::iterator iter = myMapOfActors.begin(); + for ( ; iter != myMapOfActors.end(); ++iter ) + if ( GEOM_Actor* anActor = iter.value() ) + anActor->Delete(); myMapOfActors.clear(); } @@ -99,26 +103,26 @@ bool SMESH_PreviewActorsCollection::Init( const TopoDS_Shape& theShape, TopAbs_S TopExp_Explorer exp( theShape, theType ); for ( ; exp.More(); exp.Next() ) { int index = myMapOfShapes.FindIndex( exp.Current() ); - if ( index ) { + if ( index && !myMapOfActors.contains( index ) ) { // create actor if the index is present if ( GEOM_Actor* anActor = createActor( exp.Current() )) { - // Create new entry for actor - QString aString = theEntry; - aString += QString("_%1").arg( index ); // add index to actor entry - - // Create interactive object - Handle( SALOME_InteractiveObject ) anIO = new SALOME_InteractiveObject(); - anIO->setEntry( aString.toLatin1().constData() ); - - // Init Actor - anActor->SetVectorMode( true ); - anActor->setIO( anIO ); - anActor->SetSelector( mySelector ); - anActor->SetPickable( true ); - anActor->SetResolveCoincidentTopology( true ); - - // Add Actor to the Actors Map - myMapOfActors.insert(index, anActor); + // Create new entry for actor + QString aString = theEntry; + aString += QString("_%1").arg( index ); // add index to actor entry + + // Create interactive object + Handle( SALOME_InteractiveObject ) anIO = new SALOME_InteractiveObject(); + anIO->setEntry( aString.toLatin1().constData() ); + + // Init Actor + anActor->SetVectorMode( true ); + anActor->setIO( anIO ); + anActor->SetSelector( mySelector ); + anActor->SetPickable( true ); + anActor->SetResolveCoincidentTopology( true ); + + // Add Actor to the Actors Map + myMapOfActors.insert(index, anActor); } } } diff --git a/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx b/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx index b5b8b6490..0d0a79ca0 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx @@ -80,7 +80,8 @@ StdMeshersGUI_SubShapeSelectorWdg ::StdMeshersGUI_SubShapeSelectorWdg( QWidget * parent ): - QWidget( parent ) + QWidget( parent ), + myPreviewActor( 0 ) { QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) ); @@ -118,14 +119,17 @@ StdMeshersGUI_SubShapeSelectorWdg StdMeshersGUI_SubShapeSelectorWdg::~StdMeshersGUI_SubShapeSelectorWdg() { if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) { - myPreviewActor->RemoveFromRender( myRenderer ); - aViewWindow->Repaint(); + if ( myPreviewActor ) { + myPreviewActor->RemoveFromRender( myRenderer ); + aViewWindow->Repaint(); + + delete myPreviewActor; + myPreviewActor = 0; + } } myEntry = ""; myParamValue = ""; myMainShape.Nullify(); - - delete myPreviewActor; } //================================================================================ @@ -164,6 +168,9 @@ void StdMeshersGUI_SubShapeSelectorWdg::init() void StdMeshersGUI_SubShapeSelectorWdg::showPreview( bool visible) { + if ( !myPreviewActor ) + return; + if ( myIsShown != visible ) { myPreviewActor->SetShown( visible ); @@ -180,6 +187,9 @@ void StdMeshersGUI_SubShapeSelectorWdg::showPreview( bool visible) //================================================================================= void StdMeshersGUI_SubShapeSelectorWdg::SelectionIntoArgument() { + if ( !myPreviewActor ) + return; + mySelectedIDs.clear(); // get selected mesh @@ -309,6 +319,9 @@ void StdMeshersGUI_SubShapeSelectorWdg::onRemove() //================================================================================= void StdMeshersGUI_SubShapeSelectorWdg::onListSelectionChanged() { + if ( !myPreviewActor ) + return; + mySelectionMgr->clearSelected(); TColStd_MapOfInteger aIndexes; QList selItems = myListWidget->selectedItems(); @@ -345,7 +358,7 @@ void StdMeshersGUI_SubShapeSelectorWdg::updateState() myAddButton->setEnabled( state ); myRemoveButton->setEnabled( state ); - if (state = true) { + if (state) { myPreviewActor = new SMESH_PreviewActorsCollection(); myPreviewActor->SetSelector( mySelector ); //myPreviewActor->Init( myMainShape, TopAbs_EDGE, myEntry ); -- 2.39.2