FreeCAD icon indicating copy to clipboard operation
FreeCAD copied to clipboard

Auto reorder feature on BaseFeature change broken

Open chennes opened this issue 8 months ago • 1 comments

In https://github.com/realthunder/FreeCAD/commit/ad5c54e9fea30bc3dd47e27a39a69c2020377a3d a chunk of code was added with the description "PartDesign: auto reorder feature on BaseFeature change". In it, you have:

            auto body = Body::findBodyOf(this);
            if (body) {
                if (prop == &BaseFeature && BaseFeature.getValue()) {
                    int idx = -1;
                    body->Group.find(this->getNameInDocument(), &idx);
                    int baseidx = -1;
                    body->Group.find(BaseFeature.getValue()->getNameInDocument(), &idx);  // Problem
                    if (idx >= 0 && baseidx >= 0 && baseidx+1 != idx)
                        body->insertObject(BaseFeature.getValue(), this);
                }
            }

The static analyzer caught that baseidx wasn't getting updated: the line I've marked // Problem above should be

                    body->Group.find(BaseFeature.getValue()->getNameInDocument(), &baseidx);

But, when that is changed, and so finally body->insertObject() is called, we enter an infinite loop as it's common for idx==baseidx. I'm working on a fix in FC Mainline PR https://github.com/FreeCAD/FreeCAD/pull/22013

chennes avatar Jun 16 '25 14:06 chennes

we enter an infinite loop as it's common for idx==baseidx.

Hi, thanks for the heads up. Could you please provide a sample project where the above condition is met?

realthunder avatar Jun 30 '25 14:06 realthunder