Salome HOME
IPAL54097: SIGSEGV in Scalar Bar Properties dialog and crash in next operation
[modules/smesh.git] / src / OBJECT / SMESH_Object.cxx
index 2997063e5ace9f902c3de26869090a20c0bf25c9..a1a69ff3fc4e4df79c066ceeaedf55cb468b1c94 100644 (file)
@@ -32,6 +32,8 @@
 #include "SMDS_Mesh.hxx"
 #include "SMDS_MeshCell.hxx"
 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
+#include "SMESHDS_Mesh.hxx"
+#include "SMESHDS_Script.hxx"
 #include "SMESH_Actor.h"
 #include "SMESH_ControlsDef.hxx"
 
@@ -54,7 +56,7 @@
 #include <stdexcept>
 #include <set>
 
-#include "utilities.h"
+#include <utilities.h>
 
 using namespace std;
 
@@ -67,7 +69,7 @@ using namespace std;
 #endif
 
 #ifdef _DEBUG_
-static int MYDEBUG = 1;
+static int MYDEBUG = 0;
 static int MYDEBUGWITHFILES = 0;//1;
 #else
 static int MYDEBUG = 0;
@@ -133,7 +135,7 @@ static int MYDEBUGWITHFILES = 0;
 //=================================================================================
 SMESH_VisualObjDef::SMESH_VisualObjDef()
 {
-  MESSAGE("---------------------------------------------SMESH_VisualObjDef::SMESH_VisualObjDef");
+  if ( MYDEBUG ) MESSAGE("-------------------------------SMESH_VisualObjDef::SMESH_VisualObjDef");
   myGrid = vtkUnstructuredGrid::New();
   myLocalGrid = false;
   ClearEntitiesFlags();
@@ -141,9 +143,8 @@ SMESH_VisualObjDef::SMESH_VisualObjDef()
 }
 SMESH_VisualObjDef::~SMESH_VisualObjDef()
 {
-  MESSAGE("---------------------------------------------SMESH_VisualObjDef::~SMESH_VisualObjDef");
-  //if ( MYDEBUG )
-    MESSAGE( "~SMESH_MeshObj - myGrid->GetReferenceCount() = " << myGrid->GetReferenceCount() );
+  if ( MYDEBUG ) MESSAGE("--------------------------------SMESH_VisualObjDef::~SMESH_VisualObjDef");
+  if ( MYDEBUG ) MESSAGE( "myGrid->GetReferenceCount() = " << myGrid->GetReferenceCount() );
   myGrid->Delete();
 }
 
@@ -248,7 +249,7 @@ void SMESH_VisualObjDef::createPoints( vtkPoints* thePoints )
 //=================================================================================
 void SMESH_VisualObjDef::buildPrs(bool buildGrid)
 {
-  MESSAGE("----------------------------------------------------------SMESH_VisualObjDef::buildPrs " << buildGrid);
+  if ( MYDEBUG ) MESSAGE("---------------------------SMESH_VisualObjDef::buildPrs " << buildGrid);
   if (buildGrid)
   {
     myLocalGrid = true;
@@ -281,8 +282,11 @@ void SMESH_VisualObjDef::buildPrs(bool buildGrid)
     myLocalGrid = false;
     if (!GetMesh()->isCompacted())
     {
-      MESSAGE("*** buildPrs ==> compactMesh!");
+      NulData(); // detach from the SMDS grid to allow immediate memory de-allocation in compactMesh()
+      if ( MYDEBUG ) MESSAGE("*** buildPrs ==> compactMesh!");
       GetMesh()->compactMesh();
+      if ( SMESHDS_Mesh* m = dynamic_cast<SMESHDS_Mesh*>( GetMesh() )) // IPAL53915
+        m->GetScript()->SetModified(false); // drop IsModified set in compactMesh()
     }
     vtkUnstructuredGrid *theGrid = GetMesh()->getGrid();
     updateEntitiesFlags();
@@ -459,7 +463,7 @@ void SMESH_VisualObjDef::buildElemPrs()
 
         SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
         {
-          // Convertions connectivities from SMDS to VTK
+          // Convert connectivities from SMDS to VTK
 
           if (aType == SMDSAbs_Volume && anElem->IsPoly() && aNbNodes > 3) { // POLYEDRE
             anIdList->Reset();
@@ -571,7 +575,10 @@ vtkUnstructuredGrid* SMESH_VisualObjDef::GetUnstructuredGrid()
 {
   if ( !myLocalGrid && !GetMesh()->isCompacted() )
   {
+    NulData(); // detach from the SMDS grid to allow immediate memory de-allocation in compactMesh()
     GetMesh()->compactMesh();
+    if ( SMESHDS_Mesh* m = dynamic_cast<SMESHDS_Mesh*>( GetMesh() )) // IPAL53915
+      m->GetScript()->SetModified(false); // drop IsModified set in compactMesh()
     updateEntitiesFlags();
     vtkUnstructuredGrid *theGrid = GetMesh()->getGrid();
     myGrid->ShallowCopy(theGrid);
@@ -697,9 +704,9 @@ SMESH_MeshObj::~SMESH_MeshObj()
 bool SMESH_MeshObj::Update( int theIsClear )
 {
   // Update SMDS_Mesh on client part
-  MESSAGE("SMESH_MeshObj::Update " << this);
+  if ( MYDEBUG ) MESSAGE("SMESH_MeshObj::Update " << this);
   if ( myClient.Update(theIsClear) || GetUnstructuredGrid()->GetNumberOfPoints()==0) {
-    MESSAGE("buildPrs");
+    if ( MYDEBUG ) MESSAGE("buildPrs");
     buildPrs();  // Fill unstructured grid
     return true;
   }
@@ -708,7 +715,7 @@ bool SMESH_MeshObj::Update( int theIsClear )
 
 bool SMESH_MeshObj::NulData()
 {
-  MESSAGE ("SMESH_MeshObj::NulData() ==================================================================================");
+  if ( MYDEBUG ) MESSAGE ("SMESH_MeshObj::NulData() =============================================");
   if (!myEmptyGrid)
   {
     myEmptyGrid = SMDS_UnstructuredGrid::New();
@@ -718,7 +725,7 @@ bool SMESH_MeshObj::NulData()
     points->SetNumberOfPoints(0);
     myEmptyGrid->SetPoints( points );
     points->Delete();
-    myEmptyGrid->BuildLinks();
+    //myEmptyGrid->BuildLinks();
   }
   myGrid->ShallowCopy(myEmptyGrid);
   return true;
@@ -901,7 +908,7 @@ void SMESH_SubMeshObj::UpdateFunctor( const SMESH::Controls::FunctorPtr& theFunc
 //=================================================================================
 bool SMESH_SubMeshObj::Update( int theIsClear )
 {
-  MESSAGE("SMESH_SubMeshObj::Update " << this)
+  if ( MYDEBUG ) MESSAGE("SMESH_SubMeshObj::Update " << this)
   bool changed = myMeshObj->Update( theIsClear );
   buildPrs(true);
   return changed;