What would be the possible factors for crash?

Hi,

I am calling 

BRepPrimAPI_MakeBox to creae a box. My application crashes when this function is called. I would like to know what could be the possible factors that crashes an application?

gp_Pnt b1p1(-1.0, -1.0, -1.0);

gp_Pnt b1p2(1.0, 1.0, 1.0);

 

gp_Pnt b2p1(0.0, 0.0, -1.0);

gp_Pnt b2p2(2.0, 2.0, 1.0);

 

TopoDS_Shape S1 = BRepPrimAPI_MakeBox(b1p1, b1p2);

TopoDS_Shape S2 = BRepPrimAPI_MakeBox(b2p1, b2p2);

 

It is crashing at the time when first object is created (shown in bold). PF crash report

Time Since Wake: 41000 seconds

 

System Integrity Protection: enabled

 

Crashed Thread: 0 Dispatch queue: com.apple.main-thread

 

Exception Type: EXC_BAD_ACCESS (SIGSEGV)

Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000087

Exception Note: EXC_CORPSE_NOTIFY

 

Termination Signal: Segmentation fault: 11

Termination Reason: Namespace SIGNAL, Code 0xb

Terminating Process: exc handler [0]

 

VM Regions Near 0x87:

-->

__TEXT 0000000106d4d000-0000000108009000 [ 18.7M] r-x/rwx SM=COW /Users/USER/Desktop/*/MyApp.app/Contents/MacOS/MyApp

 

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread

0 libTKernel.7.0.0.dylib 0x000000010d7e5689 Standard_Transient::DecrementRefCounter() const + 9

1 fff.MyApp 0x00000001071923ad opencascade::handle<TopoDS_TShape>::EndScope() + 45 (Standard_Handle.hxx:389)

2 fff.MyApp 0x0000000107192375 opencascade::handle<TopoDS_TShape>::~handle() + 21 (Standard_Handle.hxx:82)

3 fff.MyApp 0x0000000107192335 opencascade::handle<TopoDS_TShape>::~handle() + 21 (Standard_Handle.hxx:82)

4 fff.MyApp 0x0000000107192a7a TopoDS_Shape::~TopoDS_Shape() + 42 (TopoDS_Shape.hxx:46)

5 fff.MyApp 0x0000000107192a45 TopoDS_Face::~TopoDS_Face() + 21 (TopoDS_Face.hxx:34)

6 fff.MyApp 0x00000001071929a5 TopoDS_Face::~TopoDS_Face() + 21 (TopoDS_Face.hxx:34)

7 fff.MyApp 0x0000000107192596 BRepPrim_GWedge::~BRepPrim_GWedge() + 70 (BRepPrim_GWedge.hxx:67)

8 fff.MyApp 0x0000000107192545 BRepPrim_Wedge::~BRepPrim_Wedge() + 21 (BRepPrim_Wedge.hxx:31)

9 fff.MyApp 0x0000000107192475 BRepPrim_Wedge::~BRepPrim_Wedge() + 21 (BRepPrim_Wedge.hxx:31)

10 fff.MyApp 0x000000010719240a BRepPrimAPI_MakeBox::~BRepPrimAPI_MakeBox() + 42 (BRepPrimAPI_MakeBox.hxx:43)

11 fff.MyApp 0x000000010718f4e5 BRepPrimAPI_MakeBox::~BRepPrimAPI_MakeBox() + 21 (BRepPrimAPI_MakeBox.hxx:43)

12 fff.MyApp 0x0000000106d6a8d9 main + 7001 (main.cpp:200)

13 fff.MyApp 0x0000000106d68ce4 start + 52

 

Thread 1:

0 libsystem_kernel.dylib 0x00007fffa5b574e2 __workq_kernreturn + 10

1 libsystem_pthread.dylib 0x00007fffa5c3f791 _pthread_wqthread + 1426

2 libsystem_pthread.dylib 0x00007fffa5c3f1ed start_wqthread + 13

 

Thread 2:

0 libsystem_kernel.dylib 0x00007fffa5b574e2 __workq_kernreturn + 10

1 libsystem_pthread.dylib 0x00007fffa5c3f791 _pthread_wqthread + 1426

2 libsystem_pthread.dylib 0x00007fffa5c3f1ed start_wqthread + 13

 

Thread 3:

0 libsystem_kernel.dylib 0x00007fffa5b574e2 __workq_kernreturn + 10

1 libsystem_pthread.dylib 0x00007fffa5c3f791 _pthread_wqthread + 1426

2 libsystem_pthread.dylib 0x00007fffa5c3f1ed start_wqthread + 13

 

Thread 4:

0 libsystem_kernel.dylib 0x00007fffa5b574e2 __workq_kernreturn + 10

1 libsystem_pthread.dylib 0x00007fffa5c3f5fe _pthread_wqthread + 1023

2 libsystem_pthread.dylib 0x00007fffa5c3f1ed start_wqthread + 13

 

Thread 5:

0 libsystem_kernel.dylib 0x00007fffa5b574e2 __workq_kernreturn + 10

1 libsystem_pthread.dylib 0x00007fffa5c3f791 _pthread_wqthread + 1426

2 libsystem_pthread.dylib 0x00007fffa5c3f1ed start_wqthread + 13

 

Thread 6:: com.apple.NSEventThread

0 libsystem_kernel.dylib 0x00007fffa5b4f38a mach_msg_trap + 10

1 libsystem_kernel.dylib 0x00007fffa5b4e7d7 mach_msg + 55

2 com.apple.CoreFoundation 0x00007fff904d0c94 __CFRunLoopServiceMachPort + 212

3 com.apple.CoreFoundation 0x00007fff904d0121 __CFRunLoopRun + 1361

4 com.apple.CoreFoundation 0x00007fff904cf974 CFRunLoopRunSpecific + 420

5 com.apple.AppKit 0x00007fff8e14ef92 _NSEventThread + 205

6 libsystem_pthread.dylib 0x00007fffa5c3faab _pthread_body + 180

7 libsystem_pthread.dylib 0x00007fffa5c3f9f7 _pthread_start + 286

8 libsystem_pthread.dylib 0x00007fffa5c3f1fd thread_start + 13

 

Thread 0 crashed with X86 Thread State (64-bit):

rax: 0x00000000ffffffff rbx: 0x0000000000000065 rcx: 0x00007fff58eae275 rdx: 0x00007fff58ead5c0

rdi: 0x000000000000007f rsi: 0x00007fff58ead620 rbp: 0x00007fff58ead3a0 rsp: 0x00007fff58ead3a0

r8: 0x0000000000000002 r9: 0x00007fe15c548f30 r10: 0x00000001168ea100 r11: 0x000000010d7e5680

r12: 0x0000000000000065 r13: 0x00007fe15bbbd880 r14: 0x00007fff58eaf090 r15: 0x00007fff58eb1d50

rip: 0x000000010d7e5689 rfl: 0x0000000000010202 cr2: 0x0000000000000087

 

Logical CPU: 0

Error Code: 0x00000006

Trap Number: 14

 

Kindly give some references.

 

Thanks

Forum supervisor's picture

Dear Rakesh. 

Please see and use existing API. 

TopoDS_Shape S1 = BRepPrimAPI_MakeBox(p1, p2).Shape();

TopoDS_Solid SS = BRepPrimAPI_MakeBox(p1, p2).Solid();

Best Regards,

Forum supervisor

Rakesh Patil's picture

Hi,

Actually, those set of statement does work in a standalone application, just a main function. When I integrate it with my main project (which is based on Qt 5.5, VTK 6.3), it crashes. 

Note: I have not compiled OCCT with VTK. So I guess that should not cause a problem. Am I right?

Thanks

Rakesh Patil's picture

Hi,

Here is my updated piece of code:

gp_Pnt b1p1(-1.0, -1.0, -1.0);

gp_Pnt b1p2(1.0, 1.0, 1.0);

gp_Pnt b2p1(0.0, 0.0, -1.0);

gp_Pnt b2p2(2.0, 2.0, 1.0);

TopoDS_Shape S1 = BRepPrimAPI_MakeBox(b1p1, b1p2).Shape();

TopoDS_Shape S2 = BRepPrimAPI_MakeBox(b2p1, b2p2).Shape();

BRepTools::Write(S1,"/Users/rakesh/Desktop/S1.brep");

BRepTools::Write(S2,"/Users/rakesh/Desktop/S2.brep");

TopoDS_Shape fusedObject = BRepAlgoAPI_Fuse(S1, S2).Shape();

BRepTools::Write(fusedObject,"/Users/rakesh/Desktop/MainUnionObject.brep");

TopoDS_Iterator anIt (fusedObject);

for (; anIt.More(); anIt.Next())

{

   const TopoDS_Shape& aChild = anIt.Value();

   TopExp_Explorer aFaceExp (aChild, TopAbs_FACE);

   for(; aFaceExp.More(); aFaceExp.Next())

   {

       const TopoDS_Face& aFace = TopoDS::Face(aFaceExp.Current());

       TopExp_Explorer aEdgeExp (aFace, TopAbs_EDGE);

       for(; aEdgeExp.More(); aEdgeExp.Next())

       {

           std::cout << "Next edge" << std::endl;

           const TopoDS_Edge& aEdge = TopoDS::Edge(aEdgeExp.Current());

           Standard_Real f, l;

           Handle(Geom_Curve) curve = BRep_Tool::Curve(aEdge,f,l);

           BRepAdaptor_Curve curveAdaptor;

           curveAdaptor.Initialize(aEdge);

           GCPnts_UniformAbscissa myAlgo;

           Standard_Real Deflection = 1.5;

           myAlgo.Initialize (curveAdaptor ,Deflection) ;

           if ( myAlgo.IsDone() )

           {

              Standard_Integer nbr = myAlgo.NbPoints() ;

              Standard_Real param ;

              for ( Standard_Integer i = 1 ; i <= nbr ; i++ )

              {

                  param = myAlgo.Parameter (i) ;

                  gp_Pnt newPnt = curveAdaptor.Value(param);

                  std::cout << "newPnt: " << newPnt.X() << ", " << newPnt.Y() << ", " << newPnt.Z() << std::endl;

              }

       }

   }

}

Now it is not crashing at BRepPrimAPI_MakeBox(b1p1, b1p2). Rather it is crashing inside the loop. It is printing first edge coordinates and crashes. Here is the report:

0   libTKernel.7.0.0.dylib            0x0000000115ddc689 Standard_Transient::DecrementRefCounter() const + 9
1   fff.MyApp                        0x000000010f779fed opencascade::handle<Geom_BSplineCurve>::EndScope() + 45 (Standard_Handle.hxx:389)
2   fff.MyApp                        0x000000010f779fb5 opencascade::handle<Geom_BSplineCurve>::~handle() + 21 (Standard_Handle.hxx:82)
3   fff.MyApp                        0x000000010f779e75 opencascade::handle<Geom_BSplineCurve>::~handle() + 21 (Standard_Handle.hxx:82)
4   fff.MyApp                        0x000000010f779d44 GeomAdaptor_Curve::~GeomAdaptor_Curve() + 84 (GeomAdaptor_Curve.hxx:55)
5   fff.MyApp                        0x000000010f7778b5 GeomAdaptor_Curve::~GeomAdaptor_Curve() + 21 (GeomAdaptor_Curve.hxx:55)
6   fff.MyApp                        0x0000000110041ee9 BRepAdaptor_Curve::~BRepAdaptor_Curve() + 89 (BRepAdaptor_Curve.hxx:68)
7   fff.MyApp                        0x000000011003fcd5 BRepAdaptor_Curve::~BRepAdaptor_Curve() + 21 (BRepAdaptor_Curve.hxx:68)

Seems to be the issue inside the destructor. Earlier also it was crashing in side the desctructor. Any clue what am I doing wrong?

Thanks

Rakesh Patil's picture

Hi,

Is there any memory management thing which I am missing?