You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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
)
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.
The text was updated successfully, but these errors were encountered: