Reimplementing constraint solver

Discussion about the development of the Assembly workbench.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Reimplementing constraint solver

Post by DeepSOIC »

well, I have fixed it all locally already, and i'm now getting the segfault you described. Investigating...
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Reimplementing constraint solver

Post by DeepSOIC »

what bothers me most, when doing it in python console, it works =(
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Reimplementing constraint solver

Post by abdullah »

DeepSOIC wrote: Thu Apr 09, 2020 2:13 pm well, I have fixed it all locally already, and i'm now getting the segfault you described. Investigating...
Ups! That one was unexpected indeed!

In case it serves for something:

New File, select Sketcher WB, insert new Sketch, select point tool, click => crash.

Code: Select all

#0  /lib/x86_64-linux-gnu/libc.so.6(+0x3ef20) [0x7f0fcc4c8f20]
#1  /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(PyObject_Call+0x33) [0x7f0fce77e993]
#2  0x7f0fd10c6a7e in Py::Callable::apply(Py::Tuple const&) const from /home/abdullah/github/freecad-build/lib/libFreeCADGui.so+0x4a
#3  0x7f0ef4c556f6 in FCS::ParaObject::makeParameters(Base::UnsafePyHandle<FCS::ParameterStore>) from /home/abdullah/github/freecad-build/Mod/ConstraintSolver/ConstraintSolver.so+0x348
#4  0x7f0ef4d462f6 in FCS::G2D::ParaLine::makeParameters(Base::UnsafePyHandle<FCS::ParameterStore>) from /home/abdullah/github/freecad-build/Mod/ConstraintSolver/ConstraintSolver.so+0x78
#5  0x7f0ef742abb0 in Sketcher::FCSSketch::addLineSegment(Part::GeomLineSegment const&, bool) from /home/abdullah/github/freecad-build/Mod/Sketcher/Sketcher.so+0x14a
#6  0x7f0ef742a6e6 in Sketcher::FCSSketch::addGeometry(Part::Geometry const*, bool) from /home/abdullah/github/freecad-build/Mod/Sketcher/Sketcher.so+0x144
#7  0x7f0ef742a4ad in Sketcher::FCSSketch::addGeometry(std::vector<Part::Geometry*, std::allocator<Part::Geometry*> > const&, std::vector<bool, std::allocator<bool> > const&) from /home/abdullah/github/freecad-build/Mod/Sketcher/Sketcher.so+0x141
#8  0x7f0ef742a219 in Sketcher::FCSSketch::setUpSketch(std::vector<Part::Geometry*, std::allocator<Part::Geometry*> > const&, std::vector<Sketcher::Constraint*, std::allocator<Sketcher::Constraint*> > const&, int) from /home/abdullah/github/freecad-build/Mod/Sketcher/Sketcher.so+0xd7
#9  0x7f0ef7258e96 in Sketcher::SketchObject::solve(bool) from /home/abdullah/github/freecad-build/Mod/Sketcher/Sketcher.so+0xb4
It is when apply() is called, and within apply(), in here:

Code: Select all

       // Call
        Object apply( const Tuple &args ) const
        {
=>       PyObject *result = PyObject_CallObject( ptr(), args.ptr() );
            if( result == NULL )
            {
                throw Exception();
            }
            return asObject( result );
        }
I can also that v in

Code: Select all

HParaObject child = HParaObject(
            Py::Callable(reinterpret_cast<PyObject*>(v.type)).apply(Py::Tuple()));
        *v.value = child;
when it crashes is parameter p0.

Ask more if you need
DeepSOIC wrote: Thu Apr 09, 2020 2:17 pm what bothers me most, when doing it in python console, it works =(
Well yours does not crash from the UI either...
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Reimplementing constraint solver

Post by DeepSOIC »

It seems to help adding this:

Code: Select all

    Base::PyGILStateLocker lock;
before calling the type.

This should probably be placed in a variety of places in constraintsolver, I have to figure out where exactly...

Now I get a new crash, in the destructor of TaskDialog, when I close the sketch:

Code: Select all

TaskDialog::~TaskDialog()
{
    for (std::vector<QWidget*>::iterator it=Content.begin();it!=Content.end();++it) {
        delete *it; // <-- crashes here
        *it = 0;
    }
}
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Reimplementing constraint solver

Post by DeepSOIC »

I have pushed a fix for makeParameters. I'll open a discussion on this topic...
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Reimplementing constraint solver

Post by DeepSOIC »

BTW, is it possible to quickly get the old sketcher in our development branch? I want to use sketches to quickly mock up some geometry for testing with console, and the fact that sketcher is broken really gets in the way of that...
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Reimplementing constraint solver

Post by DeepSOIC »

abdullah wrote: Thu Apr 09, 2020 2:11 pm I pushed a second fix.
Thanks, all compiling fine now.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Reimplementing constraint solver

Post by abdullah »

DeepSOIC wrote: Thu Apr 09, 2020 3:14 pm BTW, is it possible to quickly get the old sketcher in our development branch? I want to use sketches to quickly mock up some geometry for testing with console, and the fact that sketcher is broken really gets in the way of that...
Quickly with compiling, sure: in SketchObject::SketchObject(), change:

Code: Select all

solvedSketch = std::make_shared<FCSSketch>();
with

Code: Select all

solvedSketch = std::make_shared<Sketch>();
If it is relevant, I may try to make an interface to change it from Python.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Reimplementing constraint solver

Post by abdullah »

DeepSOIC wrote: Thu Apr 09, 2020 2:52 pm It seems to help adding this:

Code: Select all

    Base::PyGILStateLocker lock;
before calling the type.

This should probably be placed in a variety of places in constraintsolver, I have to figure out where exactly...

Now I get a new crash, in the destructor of TaskDialog, when I close the sketch:

Code: Select all

TaskDialog::~TaskDialog()
{
    for (std::vector<QWidget*>::iterator it=Content.begin();it!=Content.end();++it) {
        delete *it; // <-- crashes here
        *it = 0;
    }
}
This may be related to the fact that I have removed the advance solver dialog, as it was getting in the middle of the new implementation.

The sketcher on this branch lacks at this moment the find DoF (hyperlink on the solver messages). I want to have other things working before setting for a common interface.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Reimplementing constraint solver

Post by DeepSOIC »

abdullah wrote: Thu Apr 09, 2020 3:30 pm If it is relevant, I may try to make an interface to change it from Python.
That would be nice, but if it gets difficult, maybe it's worth having a separate branch with new sketcher code...
Post Reply