Archived issue #0024955
Misuse of DownCast
Description
In some places over OCCT code DownCast() is used between incompatible types, e.g. casting from Geom_TrimmedCurve to Geom_BSplineCurve. Such cast will never succeed, thus the code must be revised.
The problem becomes apparent when method DownCast is made inline and template, using static_cast<> for casting pointer (made in the frames of #0024947), as compiler errors emerge:
GeomFill\GeomFill_NSections.cxx(537): error C2440: 'static_cast' : cannot convert from 'Geom_TrimmedCurve *' to 'Geom_BSplineCurve *
BRepFill\BRepFill_NSections.cxx(153): error C2440: 'static_cast' : cannot convert from 'Geom_TrimmedCurve *' to 'Geom_BSplineCurve *'
ShapeUpgrade\ShapeUpgrade_ShapeDivideAngle.cxx(76): error C2440: 'static_cast' : cannot convert from 'ShapeUpgrade_FaceDivide *' to 'ShapeUpgrade_SplitSurfaceAngle *'
AIS\AIS_Dimension.cxx(1109):error C2440: 'static_cast' : cannot convert from 'Geom_TrimmedCurve *' to 'Geom_Circle *'
\AIS\AIS_InteractiveObject.cxx(541): error C2440: 'static_cast' : cannot convert from 'PrsMgr_Presentation *' to 'Prs3d_Presentation *'
BRepOffsetAPI\BRepOffsetAPI_ThruSections.cxx(931): error C2440: 'static_cast' : cannot convert from 'Geom_TrimmedCurve *' to 'Geom_BSplineCurve *'
The problem becomes apparent when method DownCast is made inline and template, using static_cast<> for casting pointer (made in the frames of #0024947), as compiler errors emerge:
GeomFill\GeomFill_NSections.cxx(537): error C2440: 'static_cast' : cannot convert from 'Geom_TrimmedCurve *' to 'Geom_BSplineCurve *
BRepFill\BRepFill_NSections.cxx(153): error C2440: 'static_cast' : cannot convert from 'Geom_TrimmedCurve *' to 'Geom_BSplineCurve *'
ShapeUpgrade\ShapeUpgrade_ShapeDivideAngle.cxx(76): error C2440: 'static_cast' : cannot convert from 'ShapeUpgrade_FaceDivide *' to 'ShapeUpgrade_SplitSurfaceAngle *'
AIS\AIS_Dimension.cxx(1109):error C2440: 'static_cast' : cannot convert from 'Geom_TrimmedCurve *' to 'Geom_Circle *'
\AIS\AIS_InteractiveObject.cxx(541): error C2440: 'static_cast' : cannot convert from 'PrsMgr_Presentation *' to 'Prs3d_Presentation *'
BRepOffsetAPI\BRepOffsetAPI_ThruSections.cxx(931): error C2440: 'static_cast' : cannot convert from 'Geom_TrimmedCurve *' to 'Geom_BSplineCurve *'
Public activity
11 archived notes
Participants are labeled by their role within this record.
Fix pushed to CR24955, please review
In new method EdgeToBSpline(...):
Handle(Geom_Curve) aCurve = BRep_Tool::Curve (theEdge, aLoc, aFirst, aLast);
....
if (aCurve->IsKind(STANDARD_TYPE(Geom_Conic)))
{
}
If aCurve returned by BRep_Tool::Curve is Geom_TrimmedCurve with basic curve of type Geom_Conic, test for Geom_Conic is wrong.
Handle(Geom_Curve) aCurve = BRep_Tool::Curve (theEdge, aLoc, aFirst, aLast);
....
if (aCurve->IsKind(STANDARD_TYPE(Geom_Conic)))
{
}
If aCurve returned by BRep_Tool::Curve is Geom_TrimmedCurve with basic curve of type Geom_Conic, test for Geom_Conic is wrong.
In addition to previous note:
all manipulation with aCurve are inside condition
if(aCurve.IsNull())
{
...
}
it seems to be misprint, correct test is
if(aBSCurve.IsNull())
...
So, this method must be rewritten
all manipulation with aCurve are inside condition
if(aCurve.IsNull())
{
...
}
it seems to be misprint, correct test is
if(aBSCurve.IsNull())
...
So, this method must be rewritten
Thank you for remarks! Please review corrected version in the same branch
Ok
Dear BugMaster,
Branch CR24955 (and products from GIT master) was compiled on Linux, Windows platforms and tested.
[revision removed]
Number of compiler warnings:
occt component :
Linux: 17 (17 on master)
Windows: 0 (0 on master)
products component :
Linux: 11 (11 on master)
Windows: 2 (2 on master)
Regressions/Differences:
bugs modalg_2 bug23436
http://occt-tests/CR24955-master-occt/Debian60-64/bugs/modalg_2/bug23436.html
http://occt-tests/CR24955-master-occt/Windows-32-VC9/bugs/modalg_2/bug23436.html
Testing cases:
Not needed
Testing on Linux:
Total MEMORY difference: 360003780 / 359732036
Total CPU difference: 50183.990000000034 / 51526.570000000116
Testing on Windows:
Total MEMORY difference: 381930432 / 382719888
Total CPU difference: 39107.484375 / 37501.296875
There are no differences in images found by testdiff.
Branch CR24955 (and products from GIT master) was compiled on Linux, Windows platforms and tested.
[revision removed]
Number of compiler warnings:
occt component :
Linux: 17 (17 on master)
Windows: 0 (0 on master)
products component :
Linux: 11 (11 on master)
Windows: 2 (2 on master)
Regressions/Differences:
bugs modalg_2 bug23436
http://occt-tests/CR24955-master-occt/Debian60-64/bugs/modalg_2/bug23436.html
http://occt-tests/CR24955-master-occt/Windows-32-VC9/bugs/modalg_2/bug23436.html
Testing cases:
Not needed
Testing on Linux:
Total MEMORY difference: 360003780 / 359732036
Total CPU difference: 50183.990000000034 / 51526.570000000116
Testing on Windows:
Total MEMORY difference: 381930432 / 382719888
Total CPU difference: 39107.484375 / 37501.296875
There are no differences in images found by testdiff.
I have pushed fix to CR24955, please review.
The problem was that previous fix used simplified treatment for b-splines, which allowed periodic curves to be passed to GeomFill_AppSurf. That class obviously does not support periodic b-splines on input, and produces inconsistent result in that case (poles and knots as for periodic curve). This can be considered as separate issue.
Now all curves, including b-splines, are converted to b-spline using GeomConvert (thus loose periodicity, original behavior is restored).
The problem was that previous fix used simplified treatment for b-splines, which allowed periodic curves to be passed to GeomFill_AppSurf. That class obviously does not support periodic b-splines on input, and produces inconsistent result in that case (poles and knots as for periodic curve). This can be considered as separate issue.
Now all curves, including b-splines, are converted to b-spline using GeomConvert (thus loose periodicity, original behavior is restored).
The same error as was in first version:
...
Handle(Geom_Curve) aCurve = BRep_Tool::Curve (theEdge, aLoc, aFirst, aLast);
aCurve can be Geom_TrimmedCurve, so test
...
if (aCurve->IsKind(STANDARD_TYPE(Geom_Conic)))
...
can be wrong
...
Handle(Geom_Curve) aCurve = BRep_Tool::Curve (theEdge, aLoc, aFirst, aLast);
aCurve can be Geom_TrimmedCurve, so test
...
if (aCurve->IsKind(STANDARD_TYPE(Geom_Conic)))
...
can be wrong
Sorry, you are right! Please check corrected version pushed to CR24955.
Notably, tests seem to be completely insensitive to this change.
Notably, tests seem to be completely insensitive to this change.
Ok
Dear BugMaster,
Branch CR24955 (and products from GIT master) was compiled on Linux, MacOS and Windows platforms and tested.
[revision removed]
Number of compiler warnings:
occt component :
Linux: 16 (16 on master)
Windows: 0 (0 on master)
MacOS: 200 (203 on master)
products component :
Linux: 11 (11 on master)
Windows: 2 (2 on master)
Regressions/Differences:
No regressions/differences
Testing cases:
Not needed
Testing on Linux:
Total MEMORY difference: 361709680 / 361225452
Total CPU difference: 53757.34999999997 / 53202.74999999999
Testing on Windows:
Total MEMORY difference: 383369872 / 383800460
Total CPU difference: 40417.484375 / 42820.09375
There are no differences in images found by testdiff.
Branch CR24955 (and products from GIT master) was compiled on Linux, MacOS and Windows platforms and tested.
[revision removed]
Number of compiler warnings:
occt component :
Linux: 16 (16 on master)
Windows: 0 (0 on master)
MacOS: 200 (203 on master)
products component :
Linux: 11 (11 on master)
Windows: 2 (2 on master)
Regressions/Differences:
No regressions/differences
Testing cases:
Not needed
Testing on Linux:
Total MEMORY difference: 361709680 / 361225452
Total CPU difference: 53757.34999999997 / 53202.74999999999
Testing on Windows:
Total MEMORY difference: 383369872 / 383800460
Total CPU difference: 40417.484375 / 42820.09375
There are no differences in images found by testdiff.
Related records