Closed AIRCAP closed 1 month ago
I currently have this reproduced with main and releases/FreeCAD-1-0 branches in self built debug builds, but I can't reproduce it with AppImage 1.0rc1.
Will do more testing if this is a FreeCAD issue or related to 3rd party libs on my system.
Heads-up @hlorus -- this looks to be something in Measure.
1.0rc1 does not segfault, also when built from source - this must have regressed between rc1 and rc2 -- doing a git bisect atm (if only freecad was a bit quicker to compile)
git bisect good
3c1b54200dc526697f500d7e5532bccfd99ffb09 is the first bad commit
commit 3c1b54200dc526697f500d7e5532bccfd99ffb09
Author: PaddleStroke <pierrelouis.boyer@gmail.com>
Date: Tue Sep 17 09:44:58 2024 +0200
Measure: Fix quickmeasure globalplacement.
src/Mod/Measure/App/Measurement.cpp | 28 ++++++++++++----------------
src/Mod/Measure/Gui/QuickMeasure.cpp | 33 ++++++++++++++++++++++-----------
2 files changed, 34 insertions(+), 27 deletions(-)
#5 0x00007fffcc4fcf42 in Measure::Measurement::length (this=0x555557196540) at ~/src/FreeCAD/src/Mod/Measure/App/Measurement.cpp:353
353 BRepAdaptor_Curve curve(edge);
(gdb) print edge
$1 = (const TopoDS_Edge &) @0x7fffffffc600: {<TopoDS_Shape> = {myTShape = {entity = 0x0}, myLocation = {myItems = {myNode = {entity = 0x0}}}, myOrient = TopAbs_EXTERNAL}, <No data fields>}
(gdb) list
348 for (; obj != objects.end(); ++obj, ++subEl) {
349
350 // Get the length of one edge
351 TopoDS_Shape shape = getShape(*obj, (*subEl).c_str());
352 const TopoDS_Edge& edge = TopoDS::Edge(shape);
353 BRepAdaptor_Curve curve(edge);
(gdb) print shape
$2 = {myTShape = {entity = 0x0}, myLocation = {myItems = {myNode = {entity = 0x0}}}, myOrient = TopAbs_EXTERNAL}
(gdb) print *subEl
$3 = "Body.Sketch."
(gdb) print *obj
$4 = (App::DocumentObject * const&) @0x555559d13700: 0x55555ab5ff50
(gdb) print measureType
$10 = Measure::MeasureType::Line
if i understand that tight - what happens here is apparently anything selected is passed through this quick measurement thing now, which tries to figure out how big stuff is.
now QuickMeasure::addSelectionToMeasurement() will just add everything selected in order with Measurement::addReference3D() in order
every time this is called it checks whats the type of the latest thing added - and sets the static local measurementType to that.
so in this case it first adds a Sketch - whatever that is - and then a line - which sets the type to Line
then it tries to print the length - and since the type is "line" it tries to turn all selected objects into lines and find out their length
that works for lines but not for sketches ... - cause they yield a 0 object when you turn them into their line - which causes a segfault
I don't even know where to begin how to fix this... obviously the flaw here is that there is a single static variable "measurementType" which just holds the latest type of the last added object - that can only work if it is ensured one never adds an object of a different type to the list
the proper thing here would probably be to keep a list of all the types that are selected instead of just the latest ... but then how to measure that would need to be chosen based on any possible selection (how do you measure the sum of points, meshes and maybe an infinitely sized origin plane for good measure? thats not defined)
so maybe just define a new type "Type::Multiple" or something and set measurementType to that every time addReference3D() is called but its type is not equal to what the previous type was
or be lazy and just force the type to invalid ;)
correction. findType actually goes through the whole list and should already report invalid if it finds different types iun the same selection.
however Sketches have ShapeType TopAbs_WIRE -- which is not in the select - case list at all
it stands to reason that if something is encountered that is not in the switch list (default:) that then it should return Invalid
I'm preparing a PR
@AIRCAP you're a beast :rocket:
Is there an existing issue for this?
Problem description
Using the reproduction FCStd from #16630 : LoftAndSweeps1.FCStd.zip
Reproduction:
Expected outcome: Both the sketch and a single wire of the 2nd sketch are selected
Actual outcome: FreeCAD segfaults
Full version info
Subproject(s) affected?
Core
Anything else?
This also happens when first a single wire is selected and then with shift+click in the parts tree the other sketch is selected.
It also happens when a sketch is selected and then a wire created with the Draft workbench, but the sketch has to be part of a body. if the sketch isn't part of a body the segfault doesn't happen
Code of Conduct