MantisBT - Community
View Issue Details
0022786Community[OCCT] OCCT:Modeling Algorithmspublic2011-10-31 12:092012-04-03 19:17
szy 
bugmaster 
highcrash 
closedfixed 
WNTWindowsWindows7 X64
[OCCT] 6.5.2 
[OCCT] 6.5.3[OCCT] 6.5.3 
chl 934 W7
0022786: 64bit issue in AdvApp2Var
Post from the Forum - http://www.opencascade.org/org/forum/thread_22101/. [^]
"AdvApp2Var contains numerous mixes of casts from pointers to long int's. This seems to derive from f2c (Fortran-to-C) conversion, which happened years ago. This had been working for 32bit, where both pointer and long are both 32 bits. With migration to 64 bit these casts no longer work leading to loss of data and eventually wrong memory accesses and crashes.

AdvApp2Var_SysBase.cxx excerpt:
...
mcrlocv_((long int)&t[1], (long int *)&loc);
...

int mcrlocv_(long int t,
      long int *l)

{
*l = t;
return 0 ;
}


DRAW reproducer:
> pload MODELING
> explode c
> gplate res 5 0 c_1 0 c_2 0 c_3 0 c_4 0 c_5 0

This fails in 6.5.1 ros 64 bit and works fine on 32 bit.

I'm now reworking AdvApp2Var to fix these issues...

Hope this helps.
Roman

P.S. I wonder how these issues have not been caught by the OCC team earlier when testing Modeling Algorithms on 64 bit platforms. I came across them the first day when built on 64bit and launched my test suite :-(.

Windows 7 64bit.
There is an access violation (as some array indices get incorrectly computed due to wrongly processed pointers), it's converted to OSD_Exception_ACCESS_VIOLATION and is output in DRAW.
"
DRAW reproducer:
> pload MODELING
> explode c
> gplate res 5 0 c_1 0 c_2 0 c_3 0 c_4 0 c_5 0
## ==> crash
No tags attached.
? c.brep (2,649) 2011-10-31 12:09
https://tracker.dev.opencascade.org/
zip 6.5.1-fix490(ID22786).zip (312,052) 2012-03-22 12:38
https://tracker.dev.opencascade.org/
? W7 (1,026) 2012-03-26 16:10
https://tracker.dev.opencascade.org/
Issue History
2011-10-31 12:09szyNew Issue
2011-10-31 12:09szyAssigned To => jgv
2011-10-31 12:09szyFile Added: c.brep
2011-11-02 14:59szyNote Added: 0018474
2011-11-02 15:21szyNote Edited: 0018474bug_revision_view_page.php?bugnote_id=18474#r750
2011-11-25 14:44szyStatusnew => assigned
2011-12-14 18:14szyNote Added: 0018854
2011-12-14 18:14szyNote Edited: 0018854bug_revision_view_page.php?bugnote_id=18854#r1251
2012-03-22 06:26abvNote Added: 0020080
2012-03-22 06:26abvAssigned Tojgv => szy
2012-03-22 06:26abvStatusassigned => feedback
2012-03-22 12:38szyFile Added: 6.5.1-fix490(ID22786).zip
2012-03-23 10:05szyNote Added: 0020112
2012-03-23 10:05szyStatusfeedback => assigned
2012-03-23 10:05szyAssigned Toszy => abv
2012-03-23 10:05szyStatusassigned => resolved
2012-03-23 10:21abvNote Added: 0020113
2012-03-23 10:21abvStatusresolved => reviewed
2012-03-23 12:20mkvAssigned Toabv => mkv
2012-03-26 16:10mkvFile Added: W7
2012-03-26 16:12mkvNote Added: 0020141
2012-03-27 13:17mkvNote Added: 0020158
2012-03-27 13:18mkvTest case number => chl 934 W7
2012-03-27 13:18mkvAssigned Tomkv => bugmaster
2012-03-27 13:18mkvStatusreviewed => tested
2012-03-29 18:00bugmasterNote Edited: 0020158bug_revision_view_page.php?bugnote_id=20158#r3732
2012-03-29 18:00bugmasterNote Edited: 0020141bug_revision_view_page.php?bugnote_id=20141#r3734
2012-03-30 10:16bugmasterChangeset attached => occt master fadcea2c
2012-03-30 10:16bugmasterStatustested => verified
2012-03-30 10:16bugmasterResolutionopen => fixed
2012-04-03 19:17abvAssigned Tobugmaster => Roman Lygin

Notes
(0018474)
szy   
2011-11-02 14:59   
(edited on: 2011-11-02 15:21)
Additional information from the post http://www.opencascade.org/org/forum/thread_22127/. [^]
It seems analogical case with crash.
"I moved from Windows XP 64 bit to Windows 7 64 bit. On the new system the application crashes inside GeomPlate_MakeApprox ctor while it was running fine on Windows XP.

My current setup is:
OS: Windows 7 Enterprise, 6.1.7601 ServicePack 1.0
OCC: 6.5.1
compiler: VC10
build: OCC (and all other libs) built from source as x64 debug

Basically OCC seems to work. I can start the application; displaying points and lines works fine. When I try to fit a NURBS surface to a point cloud (nothing fancy, more or less copy-and-paste from the examples...) the constructor of GeomPlate_MakeApprox crashes. Stack trace attached below.

The actual reason for the crash is in macrgfl_ (AdvApp2Var_SysBase.cxx) where an array index (ioff) is calculated as 58412015, which seems to be out of bound. Although I think the root cause is somewhere upsteam. (E.g. iadt=-310073424 which also looks strange for an index.)

The code may not be optimal but it works (with identical input parameters) on Windows XP 64 bit.

> Does anyone use GeomPlate_MakeApprox successfully on Windows 7 x64?
> Any ideas how to solve this issue?

**** code snippet
...
           Standard_Integer Degree = 3;
        Standard_Integer NbPtsOnCur = 10;
        Standard_Integer NbIter = 3;
        Standard_Integer Order = 0;
        Standard_Integer MaxSeg = 9;
        Standard_Integer MaxDegree = 5;
        Standard_Real anApproxTol = 0.001;
        Standard_Real aConstrTol = Precision::Confusion();

        // define object BuildPlateSurface
        GeomPlate_BuildPlateSurface BPSurf(Degree, NbPtsOnCur, NbIter);
        // add point constraints to GeomPlate_BuildPlateSurface object
        for(int i(0); i<cloudPoints.size(); ++i)
          BPSurf.Add(new GeomPlate_PointConstraint(
          gp_Pnt(cloudPoints[i].getPoint().x, cloudPoints[i].getPoint().y, cloudPoints[i].getPoint().z),
          Order, aConstrTol));
          BPSurf.Perform();
        // make PlateSurface
          Handle(GeomPlate_Surface) plateSurf;
        // Handle(Geom_Surface) aSurf; is memeber now
          if(BPSurf.IsDone()) {
                plateSurf = BPSurf.Surface();
                // define parameter approximation
                Standard_Real dmax(Max(0.01, 10*BPSurf.G0Error()));
                // make approximation
                GeomPlate_MakeApprox approx(plateSurf, anApproxTol, MaxSeg, MaxDegree, dmax);
                aSurf = approx.Surface();
        }
...
=====
**** stack trace
> TKGeomBase.dll!macrgfl_(long * iadfld, long * iadflf, int * iphase, int * iznuti) Zeile 926 + 0x16 Bytes C++
     TKGeomBase.dll!AdvApp2Var_SysBase::mcrrqst_(int * iunit, int * isize, double * t, long * iofset, int * iercod) Zeile 3324 C++
     TKGeomBase.dll!AdvApp2Var_ApproxF2var::mma2fnc_(int * ndimen, int * nbsesp, int * ndimse, double * uvfonc, void (int *, double *, double *, int *, double *, int *, double *, int *, int *, double *, int *)* foncnp, double * tconst, int * isofav, int * nbroot, double * rootlg, int * iordre, int * ideriv, int * ndgjac, int * nbcrmx, int * ncflim, double * epsapr, int * ncoeff, double * courbe, int * nbcrbe, double * somtab, double * diftab, double * contr1, double * contr2, double * tabdec, double * errmax, double * errmoy, int * iercod) Zeile 6775 C++
     TKGeomBase.dll!AdvApp2Var_Iso::MakeApprox(const AdvApp2Var_Context & Conditions, const double U0, const double U1, const double V0, const double V1, void (int *, double *, double *, int *, double *, int *, double *, int *, int *, double *, int *)* const & Func, AdvApp2Var_Node & NodeBegin, AdvApp2Var_Node & NodeEnd) Zeile 275 C++
     TKGeomBase.dll!AdvApp2Var_ApproxAFunc2Var::ComputeConstraints(const AdvApprox_Cutting & UChoice, const AdvApprox_Cutting & VChoice, void (int *, double *, double *, int *, double *, int *, double *, int *, int *, double *, int *)* const & Func, const AdvApp2Var_Criterion & Crit) Zeile 661 C++
     TKGeomBase.dll!AdvApp2Var_ApproxAFunc2Var::ComputePatches(const AdvApprox_Cutting & UChoice, const AdvApprox_Cutting & VChoice, void (int *, double *, double *, int *, double *, int *, double *, int *, int *, double *, int *)* const & Func, const AdvApp2Var_Criterion & Crit) Zeile 449 C++
     TKGeomBase.dll!AdvApp2Var_ApproxAFunc2Var::Perform(const AdvApprox_Cutting & UChoice, const AdvApprox_Cutting & VChoice, void (int *, double *, double *, int *, double *, int *, double *, int *, int *, double *, int *)* const & Func, const AdvApp2Var_Criterion & Crit) Zeile 332 C++
     TKGeomBase.dll!AdvApp2Var_ApproxAFunc2Var::AdvApp2Var_ApproxAFunc2Var(const int Num1DSS, const int Num2DSS, const int Num3DSS, const Handle_TColStd_HArray1OfReal & OneDTol, const Handle_TColStd_HArray1OfReal & TwoDTol, const Handle_TColStd_HArray1OfReal & ThreeDTol, const Handle_TColStd_HArray2OfReal & OneDTolFr, const Handle_TColStd_HArray2OfReal & TwoDTolFr, const Handle_TColStd_HArray2OfReal & ThreeDTolFr, const double FirstInU, const double LastInU, const double FirstInV, const double LastInV, GeomAbs_IsoType FavorIso, GeomAbs_Shape ContInU, GeomAbs_Shape ContInV, const int PrecisCode, const int MaxDegInU, const int MaxDegInV, const int MaxPatch, void (int *, double *, double *, int *, double *, int *, double *, int *, int *, double *, int *)* const & Func, const AdvApp2Var_Criterion & Crit, AdvApprox_Cutting & UChoice, AdvApprox_Cutting & VChoice) Zeile 161 C++
     TKGeomAlgo.dll!GeomPlate_MakeApprox::GeomPlate_MakeApprox(const Handle_GeomPlate_Surface & SurfPlate, const double Tol3d, const int Nbmax, const int dgmax, const double dmax, const int CritOrder, GeomAbs_Shape Continuity, const double EnlargeCoeff) Zeile 401 + 0x14a Bytes C++
"

"

(0018854)
szy   
2011-12-14 18:14   
Additional information from RLN:
"Roman Lygin | reply 2011/12/08 22:22
OK. Here is the fix for this issue.

As expected, the root-cause is in use of long to store a pointer and then dereferencing it. On Linux/MacOS/gcc this works as long is 8 bytes, but does not on Windows/VisualC++ where it's 4 bytes.

The patch for 6.5.1 is attached. A few notes:
1. the patch (internal number fix490) was done over a previous patch (fix385), so this is a cumulative patch fix385+fix490. fix385 was sent to OCC a few months ago but is not integrated yet
2. for convenience, to easily see the diff between fix385 and fix490, they are put into subdirs and diff is provided. So feel free to apply just this delta to a baseline 6.5.1.
3. fix490 also includes a few other improvements in AdvApp2Var to increase robustness (avoiding unnecessary casts, use of Standard::Allocate(), ::Free(),...)
4. see also occ-fix-readme-excerpts.txt for details

The fix was tested on Visual C++ 2010 SP1 and gcc 4.1.2 64 bit.

Code review is welcomed. Please let me know if you have any comments. Of course, integration into OCC will be appreciated ;-)

Thanks,
Roman"

(0020080)
abv   
2012-03-22 06:26   
Sergey, I guess you should have already a patch provided by Roman -- could you please push it to Git for review?
(0020112)
szy   
2012-03-23 10:05   
RLN patch dedicated to fix of 64bit issues in AdvApp2Var is put in SVN.
Branch - OCC22786.
Andrey,
review it, please.
(0020113)
abv   
2012-03-23 10:21   
No remarks, please test
(0020141)
mkv   
2012-03-26 16:12   
(edited on: 2012-03-29 18:00)
Dear BugMaster,
Workbench KAS:dev:mkv-22786-occt was created from git branch CR22786_4
(and mkv-22786-products from svn trunk) and compiled on Linux platform.

Test case for this bug is chl/934/W7. It is OK.

There are not regressions in mkv-22786-products regarding to KAS:dev:products-20120321-opt

See results in /QADisk/occttests/results/KAS/dev/mkv-22786-products_23032012/lin
See reference results in /QADisk/occttests/results/KAS/dev/products-20120321-opt_22032012/lin
See test cases in /QADisk/occttests/tests/ED
N.B. In order to launch testing case you can make use the following instructions
http://doc/doku.php?id=occt:certification [^]

(0020158)
mkv   
2012-03-27 13:17   
(edited on: 2012-03-29 18:00)
Dear BugMaster,
Workbench KAS:dev:mkv-22786-occt was created from git branch CR22786_4
and compiled on Windows 64 bit platform.
Test case for this bug is chl/934/W7. It is OK.