1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-03 17:56:21 +03:00

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
This commit is contained in:
abv 2020-10-02 06:54:01 +03:00
parent 9f9490e1ae
commit f41fd243b6
3 changed files with 40 additions and 0 deletions

View 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);

View 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.");

11
tests/bugs/demo/bug31877 Normal file
View File

@ -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}