rlworkgroup / garage

A toolkit for reproducible reinforcement learning research.
MIT License
1.84k stars 309 forks source link

Issue copying GymEnv wrapping AtariPreprocessing #2284

Closed jamesborg46 closed 3 years ago

jamesborg46 commented 3 years ago

The following code results in double free or corruption (!prev) error using: atari-py 0.2.9 garage 2021.3.0 gym 0.15.7

from garage.envs import GymEnv
import gym
import gym.wrappers
import gym.envs.atari
import copy

env = gym.envs.atari.AtariEnv('breakout')
env.spec = gym.envs.registration.EnvSpec('NoFrameskip-v0')
env = gym.wrappers.AtariPreprocessing(env)
env = GymEnv(env, max_episode_length=1000)

copy.deepcopy(env)
copy.deepcopy(env)

The issue only occurs on the second deepcopy.

https://github.com/rlworkgroup/garage/blob/2c5410e65680baf2d62d53eea42cfc4344e090a7/src/garage/envs/gym_env.py#L349 Editing the above line to if 'viewer' in env.__dict__ and env.__dict__['viewer'] is not None: fixed this for me, but I did not look deeply into the issue so this might not be the most appropriate fix.