Fix a crash after a window is closed