Fix crash when closing window in the middle of a race