From f41fd243b6aea64176d1d1f36ff5696c4eca31da Mon Sep 17 00:00:00 2001 From: abv Date: Fri, 2 Oct 2020 06:54:01 +0300 Subject: [PATCH] 0031877: DRAW - some Visualization commands are not protected against uninitialized viewer Added protections in DRAW commands against accessing Null context Added test bugs demo bug31877 --- src/ViewerTest/ViewerTest.cxx | 17 +++++++++++++++++ src/ViewerTest/ViewerTest_ObjectCommands.cxx | 12 ++++++++++++ tests/bugs/demo/bug31877 | 11 +++++++++++ 3 files changed, 40 insertions(+) create mode 100644 tests/bugs/demo/bug31877 diff --git a/src/ViewerTest/ViewerTest.cxx b/src/ViewerTest/ViewerTest.cxx index 4bae4f7574..53a91da39c 100644 --- a/src/ViewerTest/ViewerTest.cxx +++ b/src/ViewerTest/ViewerTest.cxx @@ -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); diff --git a/src/ViewerTest/ViewerTest_ObjectCommands.cxx b/src/ViewerTest/ViewerTest_ObjectCommands.cxx index 318c5aba2e..cf6f8abf5e 100644 --- a/src/ViewerTest/ViewerTest_ObjectCommands.cxx +++ b/src/ViewerTest/ViewerTest_ObjectCommands.cxx @@ -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<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 index 0000000000..af9d00a624 --- /dev/null +++ b/tests/bugs/demo/bug31877 @@ -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}