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

Render freeze when window lose focus. #15

Open
Carton9 opened this issue Mar 9, 2023 · 1 comment
Open

Render freeze when window lose focus. #15

Carton9 opened this issue Mar 9, 2023 · 1 comment

Comments

@Carton9
Copy link

Carton9 commented Mar 9, 2023

from magent2.environments import battle_v4,adversarial_pursuit_v4 from pettingzoo.utils import random_demo env = adversarial_pursuit_v4.env(render_mode='human',max_cycles=200) random_demo(env, render=True, episodes=2)
For the code above, the render window will freeze when it loss focus.

@scottmayberry
Copy link

scottmayberry commented Mar 13, 2023

To solve:
Scroll to end of render.py in magent2 python library folder. Add the link pygame.event.pump() above the line if self.mode == "human":

observation = pygame.surfarray.pixels3d(self.display)
new_observation = np.copy(observation)
del observation
################
pygame.event.pump()
################
if self.mode == "human":
    pygame.display.flip()
return (
    np.transpose(new_observation, axes=(1, 0, 2))
    if mode == "rgb_array"
    else None
)

This will cause issues with using the close button. If you need to use the close button, here is another option. You will need to add import sys and from pygame.locals import QUIT to the render function in the same render.py. Then add the highlighted code below.

observation = pygame.surfarray.pixels3d(self.display)
new_observation = np.copy(observation)
del observation
###################
for event in pygame.event.get():
    if event.type == QUIT:
        pygame.quit()
        sys.exit()
###################
if self.mode == "human":
    pygame.display.flip()
return (
    np.transpose(new_observation, axes=(1, 0, 2))
    if mode == "rgb_array"
    else None
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants