ComputationalBiomechanicsLab / opensim-creator

A UI for building OpenSim models
https://opensimcreator.com
Apache License 2.0
137 stars 16 forks source link

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

Open adamkewley opened 3 weeks ago

adamkewley commented 3 weeks ago

Very specific bug:

Tracing the crash, it's a nullptr segfault. Looks like this:

adamkewley commented 3 weeks ago

Reading into this more, the bug in OpenSim Creator is subtle, but needs to be sorted:

The architectural issue here is that the UI is iterating over data that's being indirectly edited via some other mechanism (rollbacks), which wasn't being exercised before because setting a coordinate's value was usually safe (because most coordinates don't have this constraint-satisfaction thing going on).

The architectural solution is to change the core (undoable) model datastructure in OSC to not allow direct model mutation and, instead, provide an API like queueMutation(std::function<bool(OpenSim::Model&)>); which applies all mutations after the UI has finished rendering a frame, so that there's no chance that the UI becomes inconsistent with the thing it's iterating over.

(and now I'm beginning to see why retained-mode UIs separate mutation propagation from painting :wink:)