opensim-creator
opensim-creator copied to clipboard
Fix UI crashes if editing a constrained coordinate that results in a not-assemble-able model topology
Very specific bug:
- User opened model containing a mixture of coordinates, where some coordinates have
is_free_to_satisfy_contraints
set totrue
- When dragging a coordinate in the model's slider in the
Coordinates
panel, the UI will crash
Tracing the crash, it's a nullptr
segfault. Looks like this:
-
coordinate.getSpeed(state);
segfaults - Because an earlier part of the UI draw draws the
value
column, which the user is editing - The user edit is calling
coordinate.setValue(state, value);
. This is usually fine for most models. - However, with a model that has
free_to_satisfy_constraints
enabled,setValue
can throw an exception during aprojectQ
call in the implementation - If it throws an exception, OSC will detect the exception and call
model.rollback()
to try and preserve the user's model - This all occurs midway in the UI rendering loop, which has something like
for (Coordinate coord : coordinates) {}
- The iterator for that loop is invalidated by the
rollback
, because rolling back also involves callingModel::buildSystem
etc., which will re-synthesize theOpenSim::Coordinate
s