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

Fix `CoordinateCouplerConstraint` segfaults if not given coupled_coordinates_function

Open adamkewley opened this issue 2 years ago • 7 comments

Otherwise, it faults out if the function is not set?

adamkewley avatar Jan 03 '23 08:01 adamkewley

Upstreamed: https://github.com/opensim-org/opensim-core/issues/3347

adamkewley avatar Jan 03 '23 09:01 adamkewley

Reopening: @modenaxe reported that the crash may still happen

From what I understand, the bug is in OpenSim, and is probably still present in v4.5.1:

https://github.com/opensim-org/opensim-core/issues/3347

But @modenaxe mentioned that it may not happen in the latest version of OpenSim (which would be nice), but the upstream issue notes that my previous patches did not address this one yet, so it shouldn't be fixed yet. I'm not complaining about something being fixed--that's good--but it being fixed implies that the upstream issue should be closed.

adamkewley avatar Aug 15 '23 05:08 adamkewley

@modenaxe, could you help me reproduce your bug (even if it's fixed in 4.4.1, I'd prefer to have a basic reproduction)?

I have wrote a very barebones osim containing a CoordinateCouplerConstraint that uses a MultivariatePolynomialFunction. It's the most basic version I could find (order 1, dimension 1, etc.):

  • Commit: https://github.com/ComputationalBiomechanicsLab/opensim-creator/commit/8b583c1ef3e70c8bb7de17a037dedddabb510c9a
  • Model file: https://github.com/ComputationalBiomechanicsLab/opensim-creator/blob/8b583c1ef3e70c8bb7de17a037dedddabb510c9a/build_resources/test_fixtures/opensim-creator_515-2_repro.osim

But it doesn't seem to crash OpenSim 4.4, so I'm guessing that I'm missing something special that caused your crash.

Is there any insight about your model that would help me create a "broken" (in OpenSim 4.4) file that I can then park in OSC as an automated test, so that there's a lower change it will re-emerge in the future?

adamkewley avatar Aug 23 '23 08:08 adamkewley

(clearing from 0.5.2 because I'll need to collaborate with @modenaxe to figure out what the bug was and potentially fix it etc. before I can close this one)

adamkewley avatar Aug 23 '23 08:08 adamkewley

Hi @adamkewley,

sorry I just saw these messages.

Your model probably doesn't give issues because it's implementing a linear function. If you try adding the following CoordinateCouplerConstraint and MultivariatePolynomialFunction when you change the value of the independent coordinates tx rx ry, OC will freeze (at least my version 0.5.1 does).

Let me know if this works,

Luca

				<CoordinateCouplerConstraint name="CoordinateCouplerConstraint">
					<!--Constraint function of generalized coordinates (to be specified) used to evaluate the constraint errors and their derivatives, and must valid to at least 2nd order. Constraint function must evaluate to zero when coordinates satisfy the constraint.-->
					<coupled_coordinates_function>
						<MultivariatePolynomialFunction>
							<!--Coefficients of a multivariate polynomial function in order of ascending powers starting from the last dependent component.-->
							<coefficients>1 1 1 1</coefficients>
							<!--Number of input dimensions (i.e., dependent components).-->
							<dimension>3</dimension>
							<!--The largest sum of exponents in a single term.-->
							<order>1</order>
						</MultivariatePolynomialFunction>
					</coupled_coordinates_function>
					<!--List of names of the right hand side (independent) coordinates. Note the constraint function above, must be able to handle multiple coordinate values if more than one coordinate name is provided.-->
					<independent_coordinate_names>tx rx ry</independent_coordinate_names>
					<!--Name of the left-hand side (dependent) coordinate of the constraint coupling function.-->
					<dependent_coordinate_name>ty</dependent_coordinate_name>
				</CoordinateCouplerConstraint>

modenaxe avatar Aug 30 '23 12:08 modenaxe

Also, with both models the OpenSim GUI crashes when you try to select the constraint (maybe that's another bug to report to Ayman).

modenaxe avatar Aug 30 '23 12:08 modenaxe

Thanks for this information @modenaxe - I'll have a look into it

If it isn't fixed in-tree yet, then it'll probably miss the 0.5.2 windows (released sometime in the next week or two), but if I can get a reproduction I'll schedule it for the subsequent release.

adamkewley avatar Aug 30 '23 12:08 adamkewley

Hi @modenaxe , I noticed that this is still open - sorry about that.

I have added a reproduction that more closely matches what you explained (MultivariatePolynomialFunction with 3 independent coordinates, manipulate the coordinates). The reproduction is fine in the latest OSC, so I believe whatever was previously causing this bug has now been fixed.

I confirmed this by loading the same reproduction in 0.5.1, which you originally reported against. That version does crash, but the latest version does not.

I'll close this during the next release window, unless you think it's still lingering around?

adamkewley avatar Jul 29 '24 11:07 adamkewley

thank you @adamkewley , please feel free of closing if latest version does not show that

modenaxe avatar Aug 02 '24 11:08 modenaxe