opensim-creator icon indicating copy to clipboard operation
opensim-creator copied to clipboard

Fix UI crashes if editing a constrained coordinate that results in a not-assemble-able model topology

Open adamkewley opened this issue 8 months ago • 2 comments

Very specific bug:

  • User opened model containing a mixture of coordinates, where some coordinates have is_free_to_satisfy_contraints set to true
  • 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 a projectQ 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 calling Model::buildSystem etc., which will re-synthesize the OpenSim::Coordinates

adamkewley avatar Jun 14 '24 09:06 adamkewley