[fixed] [sketcher] crash on decreasing spline knot multiplicity

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
User avatar
uwestoehr
Posts: 2399
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany

Re: [sketcher] crash on decreasing spline knot multiplicity

Postby uwestoehr » Wed Nov 04, 2020 12:53 am

wmayer wrote:
Tue Nov 03, 2020 5:43 pm
So why are the weights not uniform?
No idea how you managed to break it.
Good question. After several tries I found now out how:

I start from this file:
Spline-explanation2.FCStd
tesfile-weight-bugs
(22.52 KiB) Downloaded 13 times
depicted here:
FreeCAD_pLcUWbzvej.png
initial
FreeCAD_pLcUWbzvej.png (28.19 KiB) Viewed 411 times

1. delete Constraint 3 (equality between first and third control point)
The shape of the spline is of course still the same, but the displayed distance between the knots changed:
FreeCAD_uritgwPluY.png
after deleting constraint 3
FreeCAD_uritgwPluY.png (30.26 KiB) Viewed 411 times

2. increase now the radius of the third control point.
Now the shape changed correctly:
FreeCAD_PffTP2ZX2k.png
after weight increase
FreeCAD_PffTP2ZX2k.png (30.03 KiB) Viewed 411 times

3. select the circle of the first and third point and apply an equality constraint
Now the shape has not uniform weights, despite all radii are equal:
FreeCAD_bfuNULc9e6.png
result
FreeCAD_bfuNULc9e6.png (28.37 KiB) Viewed 411 times

I think there are 2 bugs:
A: the distance between knots is incorrectly displayed after step 1
B. the weight is not reset whiley applying the equality constraint for the radiuses in step 3
User avatar
uwestoehr
Posts: 2399
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany

Re: [sketcher] crash on decreasing spline knot multiplicity

Postby uwestoehr » Wed Nov 04, 2020 1:01 am

Chris_G wrote:
Tue Nov 03, 2020 5:18 pm
links that I like :
A Primer on Bézier Curves
This is amazing. Many thanks!
wmayer
Site Admin
Posts: 17089
Joined: Thu Feb 19, 2009 10:32 am

Re: [sketcher] crash on decreasing spline knot multiplicity

Postby wmayer » Wed Nov 04, 2020 10:27 am

uwestoehr wrote:
Sun Nov 01, 2020 4:01 am
It is line 83 of \src\Gui\ViewProvider.cpp:
I have tried it with a debug build on Windows and for me it (quite reliably) crashes inside the destructor of SbImage. The callstack is:

Code: Select all

 	ucrtbased.dll!00007ffd82d11f9b()	Unknown
 	ucrtbased.dll!00007ffd82d151c5()	Unknown
>	Coin4d.dll!operator delete(void * block) Line 38	C++
 	Coin4d.dll!operator delete(void * block, unsigned __int64 __formal) Line 32	C++
 	Coin4d.dll!SbImageP::`scalar deleting destructor'(unsigned int)	C++
 	Coin4d.dll!SbImage::~SbImage() Line 244	C++
 	Coin4d.dll!SbImage::`scalar deleting destructor'(unsigned int)	C++
 	Coin4d.dll!SoImage::~SoImage() Line 296	C++
 	SketcherGui_d.pyd!SoImage::`scalar deleting destructor'(unsigned int)	C++
 	Coin4d.dll!SoBase::destroy() Line 331	C++
 	Coin4d.dll!SoBase::unref() Line 555	C++
 	Coin4d.dll!SoBaseList::truncate(const int length) Line 172	C++
 	Coin4d.dll!SoChildList::truncate(const int length) Line 199	C++
 	Coin4d.dll!SoChildList::~SoChildList() Line 94	C++
 	Coin4d.dll!SoChildList::`scalar deleting destructor'(unsigned int)	C++
 	Coin4d.dll!SoGroup::~SoGroup() Line 281	C++
 	Coin4d.dll!SoSeparator::~SoSeparator() Line 469	C++
 	SketcherGui_d.pyd!SoSeparator::`scalar deleting destructor'(unsigned int)	C++
 	Coin4d.dll!SoBase::destroy() Line 331	C++
 	Coin4d.dll!SoBase::unref() Line 555	C++
 	Coin4d.dll!SoBaseList::remove(const int index) Line 136	C++
 	Coin4d.dll!SoChildList::remove(const int index) Line 171	C++
 	Coin4d.dll!SoGroup::removeChild(int childindex) Line 506	C++
 	FreeCADGui_d.dll!Gui::coinRemoveAllChildren(SoGroup * group) Line 83	C++
 	SketcherGui_d.pyd!SketcherGui::ViewProviderSketch::rebuildConstraintsVisual() Line 5330	C++
 	SketcherGui_d.pyd!SketcherGui::ViewProviderSketch::draw(bool temp, bool rebuildinformationlayer) Line 4324	C++
...
wmayer
Site Admin
Posts: 17089
Joined: Thu Feb 19, 2009 10:32 am

Re: [sketcher] crash on decreasing spline knot multiplicity

Postby wmayer » Wed Nov 04, 2020 10:52 am

In some cases it crashes inside GeomBSplineCurve::~GeomBSplineCurve when the Geom_BSplineCurve is cleaned up. As a test I modified GeomBSplineCurve::removeKnot() to do nothing and always returns true. This way the crash doesn't occur any more so that the root problem eventually could be caused by OCCT.
User avatar
uwestoehr
Posts: 2399
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany

Re: [sketcher] crash on decreasing spline knot multiplicity

Postby uwestoehr » Thu Nov 05, 2020 2:15 am

wmayer wrote:
Wed Nov 04, 2020 10:52 am
In some cases it crashes inside GeomBSplineCurve::~GeomBSplineCurve when the Geom_BSplineCurve is cleaned up. As a test I modified GeomBSplineCurve::removeKnot() to do nothing and always returns true. This way the crash doesn't occur any more so that the root problem eventually could be caused by OCCT.
Many thanks for having a look. So we ca only file a bug report to OCC.
User avatar
uwestoehr
Posts: 2399
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany

Re: [sketcher] crash on decreasing spline knot multiplicity

Postby uwestoehr » Thu Nov 05, 2020 2:25 am

uwestoehr wrote:
Wed Nov 04, 2020 12:53 am
I think there are 2 bugs:
A: the distance between knots is incorrectly displayed after step 1
B. the weight is not reset while applying the equality constraint for the radiuses in step 3
I thought I could fix this because both is the consequence of the same bug I think. I tried to debug where in the code the spline weights are calculated out of the control point circle radii but cannot find this code.

Can anybody please give me a hint where I have to search or in what case the weight calculation is done?

What I debugged so far is that after deleting the constraint, the weight of the affected point is set to 1 while all other weights are 4. After this first set to 1, the weight is subsequently set again, this time to 3.96. This is the final result and this is the cause why the knot distance changed.
wmayer
Site Admin
Posts: 17089
Joined: Thu Feb 19, 2009 10:32 am

Re: [sketcher] crash on decreasing spline knot multiplicity

Postby wmayer » Thu Nov 05, 2020 7:18 am

uwestoehr wrote:
Thu Nov 05, 2020 2:15 am
Many thanks for having a look. So we ca only file a bug report to OCC.
No. I have looked further into the issue and I was able to narrow the actual problem. Inside the function SketchObject::modifyBSplineKnotMultiplicity() at the very end a list of superfluous geometries is deleted and for some reason this causes the later crash.

If I comment out the line delGeometry no crash occurs any more. This explains why it doesn't crash if I modify GeomBSplineCurve::removeKnot to do nothing or my script above that doesn't enter edit mode of the sketch.
However, it doesn't explain the random crashes I have observed inside GeomBSplineCurve::~GeomBSplineCurve but at this point the program is in an undefined state anyway so that everything could happen.

Now it needs some further investigation to find out why the call of delGeometry is responsible for the crash. As said above on Windows it mostly crashes inside the destructor of SbImage and thus we have to find out how deleting the geometry is related to the undefined data in the SbImage class.
wmayer
Site Admin
Posts: 17089
Joined: Thu Feb 19, 2009 10:32 am

Re: [sketcher] crash on decreasing spline knot multiplicity

Postby wmayer » Thu Nov 05, 2020 2:14 pm

I have implemented a function to delete several geometries in one step. This way it now crashes much less often and when it does then due to graphic driver issues or that the transaction objects got corrupted after a few undo/redo steps.

If the superfluous geometry isn't deleted at all I never got it to crash but it will be up to the user to remove this stuff manually.
User avatar
uwestoehr
Posts: 2399
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany

Re: [sketcher] crash on decreasing spline knot multiplicity

Postby uwestoehr » Thu Nov 05, 2020 3:34 pm

wmayer wrote:
Thu Nov 05, 2020 2:14 pm
I have implemented a function to delete several geometries in one step. This way it now crashes much less often and when it does then due to graphic driver issues or that the transaction objects got corrupted after a few undo/redo steps.
Thank you. I get now indeed only random crashes after undoing a decrease multiplicity. With random I mean, that I cannot find a recipe to trigger the crash in every case.

OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22932 (Git)
Build type: Release
Branch: master
Hash: 48365ecdbbde880ca4d1674cc0d8bae81d274d14
Python version: 3.6.8
Qt version: 5.12.6
Coin version: 4.0.0a
OCC version: 7.4.0.beta
Locale: German/Germany (de_DE)
User avatar
uwestoehr
Posts: 2399
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany

Re: [sketcher] crash on decreasing spline knot multiplicity

Postby uwestoehr » Sat Nov 07, 2020 6:45 pm

uwestoehr wrote:
Thu Nov 05, 2020 2:25 am
Can anybody please give me a hint where I have to search or in what case the weight calculation is done?
I go crazy, I debugged now several times, watched the changes in the variables but can still not find where the spline weights are calculated out of the given radiuses.
Thus any pointer to where to look in the code would help me a lot.
cron