0

I changed this sourcecode:

GeomAPI_ExtremaCurveCurve ecc(
                BRep_Tool::Curve(wd->Edge(i + 1), u11, u12),
                BRep_Tool::Curve(wd->Edge(j + 1), u21, u22)
            );

to this:

static Handle(Geom_Curve) c0 = BRep_Tool::Curve(wd->Edge(i + 1), u11, u12); 
static Handle(Geom_Curve) c1 = BRep_Tool::Curve(wd->Edge(j + 1), u21, u22);
GeomAPI_ExtremaCurveCurve ecc(c0, c1);

And that fixed it. But I am still a bit puzzled on why. Here is the doc for the GeomAPI_ExtremaCurveCurve object:

GeomAPI_ExtremaCurveCurve (const Handle< Geom_Curve > &C1, const Handle< Geom_Curve > &C2) 

I am not the greatest with pointers still, but it looks like the arguments require an immutable pointer, but the data that pointer points to can change ?

Then the BRep_Tool::Curve method:

static Handle< Geom_Curve > Curve (const TopoDS_Edge &E, Standard_Real &First, Standard_Real &Last) 

Now, as I program occasionally and in different languages, the static specifier in C++ is confusing, but here it has has to do with linkage and duration, cppref:

static - static or thread storage duration and internal linkage. 

I must add, this function is part of a threaded application and static and thread_local are in some aspects interchangeable with regards to thread storage.

Can anybody shed some light on why this fix works ?

thank you, S

sander
  • 1
  • 2
  • never used open cascade, but when you're dealing with segmentation fault, there are only two friends you have: gdb and valgrind. – Victor Feb 04 '20 at 11:41

1 Answers1

0

Question: Can anybody shed some light on why this fix works ?
Answer: 1) From the limited information that you have provided it seems that you may be accessing temp_c0 (BRep_Tool::Curve(wd->Edge(i + 1), u11, u12)), temp_c1 (BRep_Tool::Curve(wd->Edge(j + 1), u21, u22)) after they are deleted. For example function parameters and local variables gets destroyed once function call returns.
2) but static put c0 and c1 in memory section called "data", which is accessible throughout program duration.
3) And that's why it may fix the issue.
Question: Should you use static local variable in a multi-threaded application ?
Answer: static variables are not safe with multi thread application, because multiple threads can modify it, So best remove it or use mutex.
Question: I am not the greatest with pointers still, but it looks like the arguments require an immutable pointer, but the data that pointer points to can change ?
Answer: The function requires constant reference not pointer. There is a difference. Pointers can be nullptr and You can change pointers to point to other data but references must be initialized and then cannot refer to other data. And const reference means data cannot be changed.

MaKu
  • 1
  • 1