google-deepmind / google-deepmind/mujoco
data.contact.get(i) in mujoco-js / WASM leaks memory
- Dominant language
- C++
- Stars
- 15.2k
- Forks
- 1.8k
- Avg merge
- 10d 16h
- Merged PRs (30d)
- 25
Description
### Intro
CC @yuvaltassa
I'm trying to create a realtime simulation with mujoco-js and want to implement audio for collisions, so I'd like to access the contact impulse. However, none of the expected methods to retrieve contact information seem to work correctly.
### My setup
- mujoco-js 0.0.7 / WASM (not sure what mujoco version that equates; ideally that'd be documented in the npm package README)
- Firefox 147.0.2 (x64)
- CachyOS
### What's happening? What did you expect?
Trying to retrieve contacts manually using `const contact = data.contact.get(i)` will leak a lot of memory and eventually something crashes. Doing `contact.delete()` does not help.
I'd expect it to not crash on heap growth failure.
### Steps for reproduction
This quickly runs out of memory:
```ts
//
// [...]
function eachFrame() {
mujoco.mj_step(model, data);
for(let i = 0; i < data.ncon; i++) {
const contact = data.contact.get(i);
contact.delete();
}
}
```
### Minimal model for reproduction
_No response_
### Code required for reproduction
_No response_
### Confirmations
- [x] I searched the [latest documentation](https://mujoco.readthedocs.io/en/latest/overview.html) thoroughly before posting.
- [x] I searched previous [Issues](https://github.com/google-deepmind/mujoco/issues) and [Discussions](https://github.com/google-deepmind/mujoco/discussions), I am certain this has not been raised before.
Contributor guide
Assessment
This issue has not been assessed yet.