fix crash on closing the window.