]> OCCT Git - occt.git/commitdiff
0031877: DRAW - some Visualization commands are not protected against uninitialized...
authorabv <abv@opencascade.com>
Fri, 2 Oct 2020 03:54:01 +0000 (06:54 +0300)
committerabv <abv@opencascade.com>
Sun, 25 Oct 2020 05:46:49 +0000 (08:46 +0300)
Added protections in DRAW commands against accessing Null context

Added test bugs demo bug31877

src/ViewerTest/ViewerTest.cxx
src/ViewerTest/ViewerTest_ObjectCommands.cxx
tests/bugs/demo/bug31877 [new file with mode: 0644]

index 4bae4f75743e32130d399676443452ba487629d2..53a91da39c89877a793427c8ed50943974f95ad1 100644 (file)
@@ -1337,6 +1337,12 @@ static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** ar
                             ? TypeOfDispOperation_UnsetDispMode
                             : TypeOfDispOperation_SetDispMode;
   Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
+  if (aCtx.IsNull())
+  {
+    Message::SendFail ("Error: no active viewer");
+    return 1;
+  }
+
   if (aType == TypeOfDispOperation_UnsetDispMode)
   {
     if (argc == 1)
@@ -1402,6 +1408,11 @@ static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** arg
   if(argc==1) return 1;
   Standard_Integer On = Draw::Atoi(argv[1]);
   const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext();
+  if (Ctx.IsNull())
+  {
+    Message::SendFail ("Error: no active viewer");
+    return 1;
+  }
 
   if(argc==2)
   {
@@ -5634,6 +5645,12 @@ Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum theShapeType,
 
   // step 1: prepare the data
   Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
+  if (aCtx.IsNull())
+  {
+    Message::SendFail ("Error: no active viewer");
+    return Standard_False;
+  }
+
   aCtx->RemoveFilters();
   AIS_ListOfInteractive aDispObjects;
   aCtx->DisplayedObjects (aDispObjects);
index 318c5aba2e1c00aba4d7a3d2c9d3e876a5098c7c..cf6f8abf5e16890e837aadf97f12f2f4439b2ac5 100644 (file)
@@ -701,6 +701,12 @@ static int VTrihedron (Draw_Interpretor& ,
 static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 
 {
+  if (TheAISContext().IsNull())
+  {
+    Message::SendFail ("Error: no active viewer");
+    return 1;
+  }
+
   // Declaration de booleens
   Standard_Boolean             ThereIsName;
   Standard_Boolean             ThereIsCurrent;
@@ -854,6 +860,12 @@ static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const c
   // Verification des arguments
   if ( argc!=2) {di<<argv[0]<<" error\n"; return 1;}
 
+  if (TheAISContext().IsNull())
+  {
+    Message::SendFail ("Error: no active viewer");
+    return 1;
+  }
+
   if (TheAISContext()->NbSelected() != 1)
   {
     Message::SendFail ("Error: Wrong number of selected shapes.");
diff --git a/tests/bugs/demo/bug31877 b/tests/bugs/demo/bug31877
new file mode 100644 (file)
index 0000000..af9d00a
--- /dev/null
@@ -0,0 +1,11 @@
+puts "# ======================================================================"
+puts "# 0031877: DRAW - some Visualization commands are not protected against uninitialized viewer"
+puts "# ======================================================================"
+
+puts "REQUIRED 31877 ALL: Error: no active viewer"
+
+pload VISUALIZATION
+catch {vsetdispmode 1}
+catch {vpickshapes}
+catch {vsize}
+catch {vplanetri a}