Fixed a crash that occurred when a window closed.