You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to create mj_data using model=None should gracefully fail or throw an error, but hangs forever
Steps for reproduction
Run attached code
Minimal model for reproduction
No model needed
Code required for reproduction
importmujocoprint(
"Trying to create mj_data using model=None. This should gracefully fail or throw an error"
)
mj_data=mujoco.MjData(None)
print("Created mj_data")
Hey,
I've tested this out as well, and my kernel crashes every time when calling mujoco.MjData(None).
I think the issue occurs because the constructor doesn't properly handle a None model input, leading to an infinite loop or memory access violation in MuJoCo's backend. Instead of throwing a Python exception, it completely freezes or crashes the interpreter.
Steps I Took to Reproduce the Crash
I ran the following minimal test:
importmujocoprint("Trying to create MjData with None...")
mj_data=mujoco.MjData(None)
print("Created MjData") # This never prints because the process crashes
Expected behavior: It should gracefully fail with an error message.
Observed behavior: The Python kernel crashes, and the session needs to be restarted.
Proposed Fix
To prevent this, MjData.__init__ should explicitly check for None and raise a ValueError.
classMjData:
def__init__(self, model):
ifmodelisNone:
raiseValueError("MjData cannot be initialized with None. Provide a valid mjModel instance.")
self.model=model# Normal initialization continues here
This ensures that instead of a crash, users get a clear error message.
Would love to hear your thoughts on this! I can open a PR if needed.
Intro
Hi,
I'm an advanced user
My setup
MuJoCo, python, OSX
What's happening? What did you expect?
Trying to create mj_data using model=None should gracefully fail or throw an error, but hangs forever
Steps for reproduction
Run attached code
Minimal model for reproduction
No model needed
Code required for reproduction
Confirmations
The text was updated successfully, but these errors were encountered: