Skip to content

fix(actuators): prevent cross-type parameter leakage in default classes - #3563

Open
anishesg wants to merge 2 commits into
google-deepmind:mainfrom
proudhare:fix/ph-issue-3561
Open

fix(actuators): prevent cross-type parameter leakage in default classes#3563
anishesg wants to merge 2 commits into
google-deepmind:mainfrom
proudhare:fix/ph-issue-3561

Conversation

@anishesg

@anishesg anishesg commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

When multiple actuator shortcut types (e.g., <position>, <motor>, <velocity>) are defined within the same default class, they all write to the same actuator struct, causing parameters from one type to leak into others.

The fix clears the parameter arrays (gainprm, biasprm, dynprm) in the XML parser before setting type-specific values. This happens in OneActuator() right after determining the actuator type, but before reading XML attributes for inheritance.

This approach:

  • Prevents cross-type parameter contamination in default classes
  • Preserves same-type inheritance (e.g., <position kp="5"/> under a <position kv="3"/> default correctly inherits kv=3)
  • Leaves general and plugin actuators unaffected

The key insight is that parameters must be cleared before reading attributes (which use current values as defaults), not after in the mjs_setTo* functions.

Fixes #3561

…ross-type default inheritance

Actuator defaults defined for one subclass (such as `<position>`) were incorrectly being inherited by other actuator types (like `<motor>`, `<muscle>`, `<damper>`, etc.) when those actuators were created using the same default class. This happened because the bias parameters were not being cleared when converting an actuator to a specific type.

Signed-off-by: anish <anishesg@users.noreply.github.com>
@jonathanembleyriches

Copy link
Copy Markdown

Thanks for looking at this, but I don't think this addresses the core requirements of #3561. Every actuator shortcut in a default class writes into the same actuator struct, so they still clobber each other while the default is parsed. Zeroing biasprm in the mjs_setTo* functions only clears part of the leak. In the issue's example the motor's biasprm was never used anyway, and gain and dynamics parameters still leak across types. It also breaks same-type inheritance: <position kp="5"/> under a <position kv="3"/> default now loses its kv.

…pecific setup

Move parameter clearing from mjs_setTo* functions to the XML reader's
OneActuator function. This prevents cross-type parameter leakage when
multiple actuator shortcuts are defined in the same default class, while
preserving same-type inheritance (e.g., position under position default).

The key insight is that parameters should be cleared before reading XML
attributes for inheritance, not after. This way:
- Cross-type contamination is prevented (different types start fresh)
- Same-type inheritance works (inherited params are read before calling mjs_setTo*)
- General and plugin actuators are unaffected

Signed-off-by: anish <anishesg@users.noreply.github.com>
@anishesg

Copy link
Copy Markdown
Contributor Author

good catch, moved the fix to the XML parser. now clears gainprm/biasprm/dynprm before reading attributes for inheritance, so cross-type leakage is prevented but same-type inheritance still works

@anishesg anishesg changed the title fix(actuators): clear bias parameters in setTo functions to prevent cross-type default inheritance fix(actuators): prevent cross-type parameter leakage in default classes Sep 11, 2026
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.

Loading MJCF in python that contains an actuator subclass default overwrites other subclass params

2 participants