From f7e6593910ccc22babaf670607ffcd8b90f5bf37 Mon Sep 17 00:00:00 2001 From: Adam Jakubek Date: Mon, 29 Aug 2022 21:52:07 +0200 Subject: [PATCH] LibGUI: Fix assertion when handling removal of FileSystemModel's root This commit fixes FileSystemModel behaviour when the root path of the model has been deleted. In this case, the model index resolved for the root path is invalid and passing it to 'begin_delete_rows' would trigger assertion failure. Instead of deleting all children rows one by one, we simply invalidate the whole model. --- Userland/Libraries/LibGUI/FileSystemModel.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Userland/Libraries/LibGUI/FileSystemModel.cpp b/Userland/Libraries/LibGUI/FileSystemModel.cpp index dae02d35b9..9872055acf 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.cpp +++ b/Userland/Libraries/LibGUI/FileSystemModel.cpp @@ -418,6 +418,12 @@ void FileSystemModel::handle_file_event(Core::FileWatcherEvent const& event) break; } + if (&child.value() == m_root) { + // Root directory of the filesystem model has been removed. All items became invalid. + invalidate(); + break; + } + auto index = child->index(0); begin_delete_rows(index.parent(), index.row(), index.row());