Fixed a crash on closing windows on exit