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

0028306: Visualization - viewer crashes if style for shaded display is set to HATCH

Fixed NULL-dereference in OpenGl_Context::SetPolygonHatchStyle().
This commit is contained in:
kgv 2017-01-03 16:58:41 +03:00 committed by apn
parent acc909a893
commit ec7c343f23
4 changed files with 56 additions and 17 deletions

View File

@ -49,7 +49,7 @@ public:
//! EdgeWidth : 1.0 //! EdgeWidth : 1.0
//! FrontMaterial : NOM_BRASS //! FrontMaterial : NOM_BRASS
//! BackMaterial : NOM_BRASS //! BackMaterial : NOM_BRASS
//! HatchStyle : Aspect_HS_VERTICAL //! HatchStyle : Aspect_HS_SOLID
//! //!
//! Display of back-facing filled polygons. //! Display of back-facing filled polygons.
//! No distinction between external and internal faces of FillAreas. //! No distinction between external and internal faces of FillAreas.

View File

@ -3231,6 +3231,11 @@ bool OpenGl_Context::SetPolygonHatchEnabled (const bool theIsEnabled)
// ======================================================================= // =======================================================================
Standard_Integer OpenGl_Context::SetPolygonHatchStyle (const Handle(Graphic3d_HatchStyle)& theStyle) Standard_Integer OpenGl_Context::SetPolygonHatchStyle (const Handle(Graphic3d_HatchStyle)& theStyle)
{ {
if (theStyle.IsNull())
{
return 0;
}
if (myHatchStyles.IsNull()) if (myHatchStyles.IsNull())
{ {
if (!GetResource ("OpenGl_LineAttributes", myHatchStyles)) if (!GetResource ("OpenGl_LineAttributes", myHatchStyles))

View File

@ -1440,39 +1440,44 @@ static int VSetInteriorStyle (Draw_Interpretor& theDI,
theDI.PrintHelp (theArgVec[0]); theDI.PrintHelp (theArgVec[0]);
return 1; return 1;
} }
Standard_Integer anInterStyle = Aspect_IS_SOLID; Aspect_InteriorStyle anInterStyle = Aspect_IS_SOLID;
TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]); TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]);
aStyleArg.LowerCase(); aStyleArg.LowerCase();
if (aStyleArg == "empty") if (aStyleArg == "empty")
{ {
anInterStyle = 0; anInterStyle = Aspect_IS_EMPTY;
} }
else if (aStyleArg == "hollow") else if (aStyleArg == "hollow")
{ {
anInterStyle = 1; anInterStyle = Aspect_IS_HOLLOW;
} }
else if (aStyleArg == "hatch") else if (aStyleArg == "hatch")
{ {
anInterStyle = 2; anInterStyle = Aspect_IS_HATCH;
} }
else if (aStyleArg == "solid") else if (aStyleArg == "solid")
{ {
anInterStyle = 3; anInterStyle = Aspect_IS_SOLID;
} }
else if (aStyleArg == "hiddenline") else if (aStyleArg == "hiddenline")
{ {
anInterStyle = 4; anInterStyle = Aspect_IS_HIDDENLINE;
}
else if (aStyleArg == "point")
{
anInterStyle = Aspect_IS_POINT;
} }
else else
{ {
anInterStyle = aStyleArg.IntegerValue(); const Standard_Integer anIntStyle = aStyleArg.IntegerValue();
} if (anIntStyle < Aspect_IS_EMPTY
if (anInterStyle < Aspect_IS_EMPTY || anIntStyle > Aspect_IS_POINT)
|| anInterStyle > Aspect_IS_HIDDENLINE) {
{ std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), "
std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), " << Aspect_IS_POINT << " (Aspect_IS_POINT)]\n";
<< Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n"; return 1;
return 1; }
anInterStyle = (Aspect_InteriorStyle )anIntStyle;
} }
if (!aName.IsEmpty() if (!aName.IsEmpty()
@ -1490,7 +1495,12 @@ static int VSetInteriorStyle (Draw_Interpretor& theDI,
const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes(); const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes();
Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect(); Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect();
Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect(); Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect();
aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle); aFillAspect->SetInteriorStyle (anInterStyle);
if (anInterStyle == Aspect_IS_HATCH
&& aFillAspect->HatchStyle().IsNull())
{
aFillAspect->SetHatchStyle (Aspect_HS_VERTICAL);
}
aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True); aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True);
} }
} }
@ -2228,7 +2238,14 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
TCollection_AsciiString anArgHatch (theArgVec[++anArgIter]); TCollection_AsciiString anArgHatch (theArgVec[++anArgIter]);
if (anArgHatch.Length() <= 2) if (anArgHatch.Length() <= 2)
{ {
aChangeSet->StdHatchStyle = Draw::Atoi (anArgHatch.ToCString()); const Standard_Integer anIntStyle = Draw::Atoi (anArgHatch.ToCString());
if (anIntStyle < 0
|| anIntStyle >= Aspect_HS_NB)
{
std::cout << "Error: hatch style is out of range [0, " << (Aspect_HS_NB - 1) << "]!\n";
return 1;
}
aChangeSet->StdHatchStyle = anIntStyle;
} }
else else
{ {
@ -5652,6 +5669,7 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
"\n\t\t: [-isoontriangulation 0|1]" "\n\t\t: [-isoontriangulation 0|1]"
"\n\t\t: [-setMaxParamValue {value}]" "\n\t\t: [-setMaxParamValue {value}]"
"\n\t\t: [-setSensitivity {selection_mode} {value}]" "\n\t\t: [-setSensitivity {selection_mode} {value}]"
"\n\t\t: [-setHatch HatchStyle]"
"\n\t\t: Manage presentation properties of all, selected or named objects." "\n\t\t: Manage presentation properties of all, selected or named objects."
"\n\t\t: When -subshapes is specified than following properties will be" "\n\t\t: When -subshapes is specified than following properties will be"
"\n\t\t: assigned to specified sub-shapes." "\n\t\t: assigned to specified sub-shapes."

16
tests/bugs/vis/bug28306 Normal file
View File

@ -0,0 +1,16 @@
puts "============"
puts "OCC28306 Visualization - viewer crashes if style for shaded display is set to HATCH"
puts "============"
puts ""
vclear
vinit View1
pload MODELING VISUALIZATION
box b 10 10 10
vclear
vinit View1
vdisplay -dispMode 1 b
vfit
vsetinteriorstyle b 2
vdump $imagedir/${casename}.png