Fix error when closing last window