Fixed rare race condition crash.

BS-1164138068: Crash when accepting a messagebox while engine is
stopping.