Archived issue #0023855
Old BOPs fail on Win7 64bit when using TBB
Description
Old BOPs fail when using OCCT with TBB on an 64 bit Windows7.
Investigations show that the lines (30/31):
const TopOpeBRepDS_ListOfInterference* l1 = (const TopOpeBRepDS_ListOfInterference*)(*((long int*)v1));
const TopOpeBRepDS_ListOfInterference* l2 = (const TopOpeBRepDS_ListOfInterference*)(*((long int*)v2));
in TopOpeBRep_sort.cxx, in the compll-method obtain pointers that apparently do not point at valid objects and so the line 32 causes the exception:
if (l1->Extent() == 0) return (0);
The problem occurs only when MMGT_OPT=2.
32 bit version is not affected.
Investigations show that the lines (30/31):
const TopOpeBRepDS_ListOfInterference* l1 = (const TopOpeBRepDS_ListOfInterference*)(*((long int*)v1));
const TopOpeBRepDS_ListOfInterference* l2 = (const TopOpeBRepDS_ListOfInterference*)(*((long int*)v2));
in TopOpeBRep_sort.cxx, in the compll-method obtain pointers that apparently do not point at valid objects and so the line 32 causes the exception:
if (l1->Extent() == 0) return (0);
The problem occurs only when MMGT_OPT=2.
32 bit version is not affected.
Steps to reproduce
Make sure the following environment variables are set:
set MMGT_OPT=2
set MMGT_REENTRANT=1
and then run DRAW:
pload ALL
psphere s1 10
psphere s2 10
common result s1 s2
... exception is thrown.
The script runs without problems if either MMGT_OPT=1 or MMGT_OPT=0.
set MMGT_OPT=2
set MMGT_REENTRANT=1
and then run DRAW:
pload ALL
psphere s1 10
psphere s2 10
common result s1 s2
... exception is thrown.
The script runs without problems if either MMGT_OPT=1 or MMGT_OPT=0.
Public activity
11 archived notes
Participants are labeled by their role within this record.
Dear Roman,
can I please ask you to check if you can confirm this problem?
I know you have great experience with Intel TBB so maybe you could give a hint what causes such behaviour.
Thanks
Author
can I please ask you to check if you can confirm this problem?
I know you have great experience with Intel TBB so maybe you could give a hint what causes such behaviour.
Thanks
Author
Hi Julia,
This has nothing to do with TBB actually. This code will equally fail with any allocator. TBB just seems to provoke it more aggressively, what is good.
The root-cause is likely the same as in #0022786: wrong pointer arithmetic and attempt to store a pointer in long int. On Windows 64, the size of long int is 32 bit so it loses part of the pointer.
It looks like it input parameters v1 and v2 are pointers to pointers, so following should work:
const TopOpeBRepDS_ListOfInterference* l1 = *(const TopOpeBRepDS_ListOfInterference**)(v1);
For C++ code you might want to prefer more strict reinterpret_cast<> to C-style casting:
const TopOpeBRepDS_ListOfInterference* l1 = *reinterpret_cast<const TopOpeBRepDS_ListOfInterference**>(v1);
But please check the semantics and test.
Hope this helps.
Roman
This has nothing to do with TBB actually. This code will equally fail with any allocator. TBB just seems to provoke it more aggressively, what is good.
The root-cause is likely the same as in #0022786: wrong pointer arithmetic and attempt to store a pointer in long int. On Windows 64, the size of long int is 32 bit so it loses part of the pointer.
It looks like it input parameters v1 and v2 are pointers to pointers, so following should work:
const TopOpeBRepDS_ListOfInterference* l1 = *(const TopOpeBRepDS_ListOfInterference**)(v1);
For C++ code you might want to prefer more strict reinterpret_cast<> to C-style casting:
const TopOpeBRepDS_ListOfInterference* l1 = *reinterpret_cast<const TopOpeBRepDS_ListOfInterference**>(v1);
But please check the semantics and test.
Hope this helps.
Roman
Ohh, just realized that this was Author who reassigned this to me initially. Anyway, hope this will help to both of you, Author and Julia.
One observation: The problem does not occur with tbb42_20131003oss.
I have just came across this issue when running the regression test on Windows 64bit:
test bugs fclasses bug23237
The fix has been pushed into the repository.
I have also fixed some warning "unreachable code" (interesting which the compiler did not trigger it on the original code).
As mentioned earlier, the root-cause has nothing to do with TBB. It's just plain wrong casting a pointer to long int which may fail on Windows 64 regardless of the underlying allocator.
test bugs fclasses bug23237
The fix has been pushed into the repository.
I have also fixed some warning "unreachable code" (interesting which the compiler did not trigger it on the original code).
As mentioned earlier, the root-cause has nothing to do with TBB. It's just plain wrong casting a pointer to long int which may fail on Windows 64 regardless of the underlying allocator.
Just small comment:
the copy seems to be redundant since #0024489
+ Standard_Address p = T; + Standard::Free(p);
the copy seems to be redundant since #0024489
Right. However I intentionally left it as is, to ease backporting to previous versions of OCC (I had to apply it to 6.7.0 at least).
Re #0024489 I have a comment to be posted there.
Re #0024489 I have a comment to be posted there.
Reviewed, please test. Sorry I have added one more commit to make the code around more readable (mostly adding line breaks between operators).
Please test also on 64-bit Windows!
Dear Commenter 1,
Branch CR23855 (and products from GIT master) was compiled on Linux and Windows platforms and tested.
[revision removed]
Number of compiler warnings:
occt component :
Linux: 48 (48 on master)
Windows: 1 (1 on master)
products component :
Linux: 12 (12 on master)
Windows: 2 (2 on master)
Regressions/Differences:
No regressions/differences
Testing cases:
Not needed
Testing on Linux:
Total MEMORY difference: 365200936 / 365947140
Total CPU difference: 43948.98999999988 / 44021.22000000015
Testing on Windows:
Total MEMORY difference: 417067404 / 417396220
Total CPU difference: 32577.796875 / 32472.65625
There are not differences in images found by testdiff.
Branch CR23855 (and products from GIT master) was compiled on Linux and Windows platforms and tested.
[revision removed]
Number of compiler warnings:
occt component :
Linux: 48 (48 on master)
Windows: 1 (1 on master)
products component :
Linux: 12 (12 on master)
Windows: 2 (2 on master)
Regressions/Differences:
No regressions/differences
Testing cases:
Not needed
Testing on Linux:
Total MEMORY difference: 365200936 / 365947140
Total CPU difference: 43948.98999999988 / 44021.22000000015
Testing on Windows:
Total MEMORY difference: 417067404 / 417396220
Total CPU difference: 32577.796875 / 32472.65625
There are not differences in images found by testdiff.
Dear Commenter 1,
Branch CR23855 (and products from GIT master) was compiled on 64-bit Windows platform and tested.
No regressions/differences
Testing cases:
bugs modalg_5 bug23855 - OK.
Branch CR23855 (and products from GIT master) was compiled on 64-bit Windows platform and tested.
No regressions/differences
Testing cases:
bugs modalg_5 bug23855 - OK.
Related records