Fix crashes caused by rendering to a surface on teardown