Fix segfault on osx when closing a window and a least another window is still open