If the user deletes the original empty buffer (:bw!) between hide and restore, nvim_win_set_buf would error. Now falls back to closing the window if the original buffer is invalid.