bullet3 icon indicating copy to clipboard operation
bullet3 copied to clipboard

Make sure MJCFBaseBulletEnv.render returns a uint8 array

Open muupan opened this issue 4 years ago • 1 comments

The issue is MJCFBaseBulletEnv.render returns an int64 array.

Here is how to reproduce the issue.

import gym
import pybullet_envs

env = gym.make("AntBulletEnv-v0")
env.reset()
array = env.render(mode="rgb_array")
print(array.dtype)

What I get with the latest master (https://github.com/bulletphysics/bullet3/commit/abea1a848411cf53385fb8288c89db05e5751ef7): int64.

This is not great since gym's video recorder expects uint8: https://github.com/openai/gym/blob/8a721ace460cbaf8c3e6c03c12d06c616fd6e1e8/gym/wrappers/monitoring/video_recorder.py#L300

The current code of MJCFBaseBulletEnv.render seems to try to cast the array to uint8 at L129. However, it does not work since it is ignored by L130. https://github.com/bulletphysics/bullet3/blob/abea1a848411cf53385fb8288c89db05e5751ef7/examples/pybullet/gym/pybullet_envs/env_bases.py#L129-L130

This PR resolves the issue so that the code snippet above prints uint8.

muupan avatar Feb 14 '21 14:02 muupan

I'm using bullet 3.2.0, and I also struggled with this problem for a day or two.

It would be nice if the changes were reflected soon.

OnesoulKang avatar Jan 13 '22 05:01 OnesoulKang