google-deepmind / mujoco_mpc

Real-time behaviour synthesis with MuJoCo, using Predictive Control
https://github.com/deepmind/mujoco_mpc
Apache License 2.0
952 stars 142 forks source link

Seg fault when adding mjITEM_EDITTXT to defTask #191

Closed nkhosh closed 11 months ago

nkhosh commented 11 months ago

I need to add a text field to the task section of the UI for a feature I'm implementing. I add a field in task.h as such: char myText[200] = ""; And then add this line to defTask[] in agent.cc: {mjITEM_EDITTXT, "My Text", 2, ActiveTask()->myText, ""},

MJPC runs just fine but as soon as I click on the text field and edit or just click elsewhere right away, I have a seg fault in InternalResidual()->Update(); called from ThreadSafeTask::Transition. It seems like task_->parameters is undefined during this update. I have trouble understanding why this happens since the text field should not have anything to do with the parameters definition. I would really appreciate some help with this.

It's worth noting that I don't have this issue for any other type of mjtItem_, for example mjITEM_EDITINT works just fine.

Last time I merged with the repo was on Sep 14th, commit ab5edf26361323c8d4de4ee61ae40ddcca61b66c.

nimrod-gileadi commented 11 months ago

I looked into it, and I think this is because of some undocumented details of the mjUI implementation.

Specifically, the char array used for EDITTXT fields is assumed to have a length of mjMAXUITEXT, which is 300. Try replacing 200 with mjMAXUITEXT and see what happens.

nkhosh commented 11 months ago

That solves the issue and explains the seg fault. Thank you!