opensim-org / opensim-core

SimTK OpenSim C++ libraries and command-line applications, and Java/Python wrapping.
https://opensim.stanford.edu
Apache License 2.0
758 stars 307 forks source link

Asserts fail in the Component Interface #3803

Closed fcanderson closed 6 days ago

fcanderson commented 3 weeks ago

When running in Debug mode on Windows, the following asserts stop execution:

  1. Assert failed: Invalid Subsystem Index (State.h, line 48 in Simbody). The origin was initialization of the subsystem index (ssIndex) and discrete variable index (moIndex and dvIndex) in struct MondelingOptionInfo (Component.h, line 4082) and struct DiscreteVariableInfo (Component.h, line 4168). These indexes are being initialized to a value of -1, which is deemed invalid in Debug mode.
  2. Assert failed: Map/set mismatch in Xtree in the Visual Studio std::map implementation. The origin was a comparison of iterators in Component::getModelingOption() and Component::setModelingOption() in a for loop. See Component.cpp, line 658.

These popped during my development of a Catch2 unit test for the new StatesDocument class.

The 2nd assert failure is a serious bug that could cause a segmentation violation or corrupt data under certain conditions. This is a good reminder for me! Running unit tests in in Debug mode is good idea!

I have fixes for both that I will submit in a PR later today.