0025528: Visualization - Exception on removing an interactive object from a local...
authorsan <san@opencascade.com>
Thu, 4 Dec 2014 11:14:14 +0000 (14:14 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 4 Dec 2014 11:20:18 +0000 (14:20 +0300)
AIS_LocalContext::Remove() corrected to unbind the argument from
myActiveObjects at the very end. Also some code clean up applied
(e.g. duplicated AddOrRemoveSelected() call removed, formatting corrected).

code formatting

src/AIS/AIS_LocalContext.cxx
tests/bugs/vis/bug25528 [new file with mode: 0644]

index aee453f..bbad8b4 100644 (file)
@@ -445,65 +445,67 @@ void AIS_LocalContext::Deactivate(const Handle(AIS_InteractiveObject)& aSelectab
 
 Standard_Boolean AIS_LocalContext::Remove(const Handle(AIS_InteractiveObject)& aSelectable)
 {
-  if(!myActiveObjects.IsBound(aSelectable)) return Standard_False;
+  if(!myActiveObjects.IsBound (aSelectable))
+  {
+    return Standard_False;
+  }
+
+  if (IsSelected (aSelectable))
+  {
+    AddOrRemoveSelected (aSelectable, Standard_False);
+  }
+
+  const Handle(AIS_LocalStatus)& Att = myActiveObjects (aSelectable);
 
-  if(IsSelected(aSelectable))
-    AddOrRemoveSelected(aSelectable,Standard_False);
-    
-  const Handle(AIS_LocalStatus)& Att = myActiveObjects(aSelectable);
-  
   TColStd_ListIteratorOfListOfInteger It;
-  // it is checked which were the temporary attributes 
-  // and they are set to 0
 
-  // desactivate standard modes
-  if(Att->Decomposed()){
-    for(It.Initialize(myListOfStandardMode);It.More();It.Next()){
-      mySM->Deactivate(aSelectable,It.Value(),myMainVS);
+  // Deactivate standard modes
+  if (Att->Decomposed())
+  {
+    for (It.Initialize (myListOfStandardMode); It.More(); It.Next())
+    {
+      mySM->Deactivate (aSelectable, It.Value(), myMainVS);
     }
   }
-  
-  // if object or temporary presentations...
-  if(Att->IsTemporary())
+
+  // If object or temporary presentations
+  if (Att->IsTemporary())
+  {
+    if (Att->IsSubIntensityOn())
     {
-      if(Att->IsSubIntensityOn())
-       myMainPM->Unhighlight(aSelectable,Att->HilightMode());
-      
-      // remove if bug on clear correct...
-      myMainPM->Erase(aSelectable,Att->DisplayMode());
-      myMainPM->Clear(aSelectable,Att->DisplayMode());
-      if(myMainPM->IsDisplayed(aSelectable,Att->HilightMode()))
-       myMainPM->Erase(aSelectable,Att->HilightMode());
-      //       myMainPM->Clear(aSelectable,Att->HilightMode());
+      myMainPM->Unhighlight (aSelectable, Att->HilightMode());
     }
-  // if below intensity
-  else
+
+    myMainPM->Erase (aSelectable, Att->DisplayMode());
+    myMainPM->Clear (aSelectable, Att->DisplayMode());
+    if (myMainPM->IsDisplayed (aSelectable, Att->HilightMode()))
     {
-      if(Att->IsSubIntensityOn())
-       myCTX->SubIntensityOff(aSelectable);
+      myMainPM->Erase (aSelectable, Att->HilightMode());
     }
-  // desactivate stored proper modes
-  for(It.Initialize(Att->SelectionModes());It.More();It.Next()){
-    mySM->Deactivate(aSelectable,It.Value(),myMainVS);
   }
-// pop : si je laisses cela plantes dans les elements de construction  
-//       alors a toi de jouer ROB
-//  RemoveSelected(aSelectable);
+  // If subintensity used
+  else if (Att->IsSubIntensityOn())
+  {
+    myCTX->SubIntensityOff (aSelectable);
+  }
 
-  if(IsSelected(aSelectable))
-    AddOrRemoveSelected(aSelectable);
-  myActiveObjects.UnBind(aSelectable);
+  // Deactivate stored selection modes
+  for (It.Initialize (Att->SelectionModes()); It.More(); It.Next())
+  {
+    mySM->Deactivate (aSelectable, It.Value(), myMainVS);
+  }
 
   // Remove the interactive object from selection manager
   if (mySM->Contains (aSelectable))
   {
     mySM->Remove (aSelectable);
   }
-
   UpdateSort();
-
   ClearOutdatedSelection (aSelectable, Standard_True);
 
+  // This should be done at the very end because most methods use
+  // myActiveObjects even during clean-up
+  myActiveObjects.UnBind (aSelectable);
   return Standard_True;
 }
 
diff --git a/tests/bugs/vis/bug25528 b/tests/bugs/vis/bug25528
new file mode 100644 (file)
index 0000000..d02560b
--- /dev/null
@@ -0,0 +1,25 @@
+puts "============"
+puts "OCC25528"
+puts "============"
+puts ""
+####################################################################################
+# Visualization - Exception on removing an interactive object from 
+# a local context
+# vremove -local <obj_name> crashes if there is an opened local context
+####################################################################################
+
+pload ALL
+box b 1 2 3
+vinit
+vdisplay b
+vfit
+
+# opening a local context for local selection
+vselmode b 4 1
+# Select a face just to simulate the scenario used in a real application
+vselect 200 200
+# This line should not lead to exception
+vremove -local b
+
+# Screenshot should be empty (box removed successfully)
+vdump ${imagedir}/${casename}.png