Skip to content

[MJCF] Improper solref setting when using unit scaling #20

@ShravanTata

Description

@ShravanTata

Description

The solref parameter is being modified directly when passed to a function due to the parameter being a list, which is passed by reference. This is causing unintended side effects when the same solref object is used across multiple calls.

Reproduction

  1. Pass the same solref list to multiple functions
  2. Observe that modifications persist across calls
  3. Confirmed with id(solref) remaining the same across calls

Current Behavior

if solref is not None:

The function modifies the original list directly, causing subsequent calls to operate on already-modified values.

Expected Behavior

The function should operate on a copy of the list to prevent mutations of the original object.

Proposed Fix

Create a local copy of the list:

if solref is not None:
    scaled_solref = solref.copy()
    if all(sol < 0 for sol in local_solref):
        scaled_solref[0] *= units.newtons/units.meters
        scaled_solref[1] *= units.newtons/units.velocity
    else:
        scaled_solref[0] *= units.seconds

Metadata

Metadata

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions