Fixes clean up code, should not call opengl functions withut valid context.