-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Labels
bugSomething isn't workingSomething isn't working
Description
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
- Pass the same
solreflist to multiple functions - Observe that modifications persist across calls
- Confirmed with
id(solref)remaining the same across calls
Current Behavior
farms_mujoco/farms_mujoco/simulation/mjcf.py
Line 256 in 8f02900
| 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.secondsjarreguit
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working