Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Report] 'rgb_render' mode in MPE produces a black screen #864

Closed
1 task done
bergem1t opened this issue Dec 16, 2022 · 2 comments · Fixed by #874
Closed
1 task done

[Bug Report] 'rgb_render' mode in MPE produces a black screen #864

bergem1t opened this issue Dec 16, 2022 · 2 comments · Fixed by #874
Labels
bug Something isn't working

Comments

@bergem1t
Copy link

Describe the bug

When calling env.render() on an MPE environment with rgb_array render mode, I get a black screen. I tested it with simple_v2 and 'simple_adversary_v2'. It does work with connect_four_v3.
It works for MPEs if I call the function draw(). draw() is called in render() for human but not rgb_array mode.

Code example

from pettingzoo.mpe import simple_v2
from matplotlib import pyplot as plt


env = simple_v2.env(render_mode='rgb_array')

env.reset()
#env.env.env.draw() <--- works if uncommented
plt.figure; plt.imshow(env.render())

System info

pip installed pettingzoo version 1.22.2
Windows 11
python 3.9.13

Additional context

No response

Checklist

  • I have checked that there is no similar issue in the repo
@bergem1t bergem1t added the bug Something isn't working label Dec 16, 2022
@cibeah
Copy link
Contributor

cibeah commented Dec 28, 2022

Hello,

I encountered the same issue. Indeed in the render method of SimpleEnv (mpe/_mpe_utils/simple_env.py, line 279) which serves as base class for other MPE envs, the numpy array for the rgb_array version is rendered as a screen grab of the pygame screen, but the image is only drawn on the screen when mode is human. Incidentally the screen grab function is called in all cases even when it seems not needed.

Code:

observation = np.array(pygame.surfarray.pixels3d(self.screen))
if self.render_mode == "human":
    self.draw()
    pygame.display.flip()
return (
    np.transpose(observation, axes=(1, 0, 2))
    if self.render_mode == "rgb_array"
    else None
)

Maybe we could have something like:

self.draw()
if self.render_mode == "rgb_array":
    observation = np.array(pygame.surfarray.pixels3d(self.screen))
    return np.transpose(observation, axes=(1, 0, 2))
if self.render_mode == "human":  
    pygame.display.flip()
return None

I can make a PR, but not sure if this is not already being fixed.

@WillDudley
Copy link
Contributor

Hello,

I encountered the same issue. Indeed in the render method of SimpleEnv (mpe/_mpe_utils/simple_env.py, line 279) which serves as base class for other MPE envs, the numpy array for the rgb_array version is rendered as a screen grab of the pygame screen, but the image is only drawn on the screen when mode is human. Incidentally the screen grab function is called in all cases even when it seems not needed.

Code:

observation = np.array(pygame.surfarray.pixels3d(self.screen))
if self.render_mode == "human":
    self.draw()
    pygame.display.flip()
return (
    np.transpose(observation, axes=(1, 0, 2))
    if self.render_mode == "rgb_array"
    else None
)

Maybe we could have something like:

self.draw()
if self.render_mode == "rgb_array":
    observation = np.array(pygame.surfarray.pixels3d(self.screen))
    return np.transpose(observation, axes=(1, 0, 2))
if self.render_mode == "human":  
    pygame.display.flip()
return None

I can make a PR, but not sure if this is not already being fixed.

This isn't currently being fixed due to lack of resources - we'd greatly appreciate a PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants