mardi 4 février 2020

C++11 : I patched a segfault, but I don't exactly know what fixed it

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

Aucun commentaire:

Enregistrer un commentaire