Fix issues with pygame event handling (#2684)

* Fix issues with pygame event handling

* Fix display initialization and exit for jupyter
This commit is contained in:
Andrew Tan Jin Shen
2022-03-12 00:37:04 +08:00
committed by GitHub
parent 29cf1e5393
commit 6f1ec7cc1b
10 changed files with 28 additions and 1 deletions

View File

@@ -269,6 +269,7 @@ class AcrobotEnv(core.Env):
def render(self, mode="human"):
if self.screen is None:
pygame.init()
pygame.display.init()
self.screen = pygame.display.set_mode((self.SCREEN_DIM, self.SCREEN_DIM))
if self.clock is None:
self.clock = pygame.time.Clock()
@@ -326,6 +327,7 @@ class AcrobotEnv(core.Env):
self.surf = pygame.transform.flip(self.surf, False, True)
self.screen.blit(self.surf, (0, 0))
if mode == "human":
pygame.event.pump()
self.clock.tick(self.metadata["render_fps"])
pygame.display.flip()
@@ -338,6 +340,7 @@ class AcrobotEnv(core.Env):
def close(self):
if self.screen is not None:
pygame.display.quit()
pygame.quit()
self.isopen = False