The constraint list follows you into a live sketch

The rows, their ✗ buttons and the click-to-highlight were all built against
m_doc.features[m_constrain_feat].entity_constraints — a COMMITTED feature. A live sketch
has no committed feature, so the card was hidden for the whole session and the list it
would have shown was empty by construction. Every constraint applied while drawing was
nameless: the badge said one existed, nothing said which.

rebuild_constraint_list now picks its source by scope. live_constraint_scope() is the same
discriminator apply_constraint already used to route to apply_live_constraint — both
Constrain modes set m_active, so is_sketching() alone would claim the live scope while the
committed manager is open. delete_constraint and highlight_constraint_entities branch on
it too, and the card shows in Sketch mode as well as Constrain.

Keeping the rows in step needed a signal that did not exist: on_solve_state fires on every
frame of a drag, so rebuilding from it would rebuild the list continuously. The tool now
fires on_constraints_changed only when the constraint SET changes — one added by
try_add_constraints, one removed by remove_constraint (the indexed form the badge click and
the ✗ row now share).

The rebuild is deferred through CallAfter. One of its callers is the ✗ button's own click
handler, and rebuild_constraint_list destroys those buttons: deleting the window whose
handler is still on the stack is a use-after-free.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011FbJKJAJxxkhDTs9XdZzKA
This commit is contained in:
Tommaso Bianchi
2026-09-01 06:45:18 +02:00
co-authored by Claude Opus 5
parent b250a2b858
commit 9858080aa0
6 changed files with 86 additions and 9 deletions
+17
View File
@@ -1494,6 +1494,23 @@ int DesignCanvas::sketch_constraint_count() const
return int(m_sketch_tool.constraints().size());
}
const std::vector<SketchEntityConstraintDef>& DesignCanvas::sketch_constraints() const
{
return m_sketch_tool.constraints();
}
bool DesignCanvas::remove_sketch_constraint(int idx)
{
const bool removed = m_sketch_tool.remove_constraint(idx);
if (removed) request_repaint();
return removed;
}
void DesignCanvas::set_on_sketch_constraints_changed(std::function<void()> cb)
{
m_sketch_tool.on_constraints_changed = std::move(cb);
}
bool DesignCanvas::try_add_sketch_constraints(const std::vector<SketchEntityConstraintDef>& defs)
{
return m_sketch_tool.try_add_constraints(defs);