fix(assembly): prevent segfault when all joints are removed
Some checks failed
Build and Test / build (pull_request) Has been cancelled
Some checks failed
Build and Test / build (pull_request) Has been cancelled
updateSolveStatus() calls solve() when lastResult_.placements is empty, but solve() calls updateSolveStatus() at the end. When an assembly has zero constraints (all joints removed), the solver returns zero placements, causing infinite recursion until stack overflow (segfault). Add a static re-entrancy guard so the recursive solve() call is skipped if updateSolveStatus() is already on the call stack.
This commit is contained in:
@@ -275,8 +275,14 @@ void AssemblyObject::updateSolveStatus()
|
||||
//+1 because there's a grounded joint to origin
|
||||
lastDoF = (1 + numberOfComponents()) * 6;
|
||||
|
||||
if (!solver_ || lastResult_.placements.empty()) {
|
||||
// Guard against re-entrancy: solve() calls updateSolveStatus(), so if
|
||||
// placements are legitimately empty (e.g. zero constraints / all parts
|
||||
// grounded) the recursive solve() would never terminate.
|
||||
static bool updating = false;
|
||||
if (!updating && (!solver_ || lastResult_.placements.empty())) {
|
||||
updating = true;
|
||||
solve();
|
||||
updating = false;
|
||||
}
|
||||
|
||||
if (!solver_) {
|
||||
|
||||
Reference in New Issue
Block a user