Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deleting an element from OpenSim::Coordinate's causes getMinRange… #3546

Merged
merged 3 commits into from
Sep 14, 2023

Conversation

adamkewley
Copy link
Contributor

@adamkewley adamkewley commented Sep 13, 2023

Fixes issue #3532

Brief summary of changes

  • Adds a runtime check for the error condition to OpenSim::Coordinate::extendFinalizeFromProperties

Testing I've completed

CHANGELOG.md (choose one)

  • updated.

This change is Reviewable

Copy link
Member

@tkuchida tkuchida left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍. Minor comment below ⬇️

// eagerly check if outside code has somehow managed to remove elements
// from this coordinate's `range` property (issue #3532)
OPENSIM_THROW_IF(
getProperty_range().size() < 2,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fewer than 2 elements doesn't make sense for a range, but neither does more than 2. Perhaps demand that the size is equal to 2?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The size might be enforced automatically via the property macro that defines it, OpenSim_DECLARE_LIST_PROPERTY_SIZE.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The size might be enforced automatically via the property macro that defines it, OpenSim_DECLARE_LIST_PROPERTY_SIZE.

The macro pumps the size to constructProperty_##name, which moves it into AbstractProperty::_minListSize etc, which will then range-check:

  • AbstractProperty::setValue
  • AbstractProperty::removeValueAtIndex

But I don't think it will currently range-check:

  • AbstractProperty::clear
  • operator=(PropertyWithNoRangeLimits const&)
  • AbstractProperty::appendValue
  • AbstractProperty::assign

With clear being the one that the test exercises, but it's also sometimes necessary (e.g. in property editors) to do stuff like create a new property, only copy over the elements the user wants, and then assign the new property over the old one, which will delete the range check :<

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think OpenSim_DECLARE_LIST_PROPERTY_SIZE should maybe have more enforcement, but that's a wider change than this specific issue.

Apart from that, I have changed the check to be == 2, rather than >= 2, if that resolves this conversation?

OpenSim/Simulation/SimbodyEngine/Coordinate.cpp Outdated Show resolved Hide resolved
Copy link
Member

@tkuchida tkuchida left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@nickbianco nickbianco merged commit 54f31eb into main Sep 14, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants