0

I get the common pygame.error: display Surface quit in my _render function as seen below. The gym environment runs, but then crashes after about 10 secs. I am new to pygame so it would help if the error was explained. I have checked here and here, but the answers don't quite solve my problem. Full code is here. When I run the program through my main.py file the program runs successfully with gym, but when I run it using the gym_test.py I get the error.

main.py

def main():
    game = Frogger(visual=False)

    while True:

        # self.game_data = game.load_sprites()

        action = game.action_space.sample()
        _, _, terminal, _ = game.step(action)

        if terminal:
            game.reset()

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()


if __name__ == '__main__':
    main()

gym_test.py

import gym
import gym_audio
import pygame
env = gym.make('Frogger-v0')

for i_episode in range(20):
    observation = env.reset()
    for t in range(100):
        env.render()
        print(observation)
        action = env.action_space.sample()
        observation, reward, done, info = env.step(action)
        if done:
            print("Episode finished after {} timesteps".format(t+1))
            pygame.quit()
            break

render.py

 def _render(self, mode='human', close=False):
        self.screen.blit(self.background, (0, 0))

Error in sys.exitfunc: Traceback (most recent call last): File "/usr/local/Cellar/python/2.7.13_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/atexit.py", line 24, in _run_exitfuncs func(*targs, **kargs) File "/usr/local/lib/python2.7/site-packages/gym/utils/closer.py", line 67, in close closeable.close() File "/usr/local/lib/python2.7/site-packages/gym/core.py", line 164, in close self.render(close=True) File "/usr/local/lib/python2.7/site-packages/gym/core.py", line 150, in render return self._render(mode=mode, close=close) File "/Users/lusenii/Developer/gym-audio/gym_audio/envs/frogger.py", line 82, in _render self.screen.blit(self.background, (0, 0)) pygame.error: display Surface quit

luii
  • 319
  • 3
  • 5
  • 16
  • You shouldn't post links to your code here, just add it [(a minimal, complete and verifiable example)](https://stackoverflow.com/help/mcve) to the question. – skrx Oct 25 '17 at 09:57
  • The error was probably raised because `pygame.quit()` was called somewhere and the game wasn't exited afterwards. `pygame.quit` doesn't actually quit the game, it just uninitializes everything. Please post the complete traceback. – skrx Oct 25 '17 at 10:17
  • @skrx I added the traceback and some additional code. – luii Oct 25 '17 at 16:25
  • I'm not familiar with Open AI and can't test your program. I can only tell you that you must not call any pygame functions after you called `pygame.quit()`, otherwise a `pygame.error` is raised. – skrx Oct 25 '17 at 20:26

0 Answers0