From bbec75f45193119bf20b690d5e3c92b8908d6abf Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Wed, 27 Jul 2022 02:35:28 +0300 Subject: [PATCH] switch to using microtasks for switching, fixing segfaults --- src/DirectoryView.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/DirectoryView.cpp b/src/DirectoryView.cpp index a092287..25417ad 100644 --- a/src/DirectoryView.cpp +++ b/src/DirectoryView.cpp @@ -4,12 +4,15 @@ DirectoryView::~DirectoryView() {} void DirectoryView::update() { - window()->start_batch(); - target()->clear_children(); - for (const auto &entry : std::filesystem::directory_iterator(m_current_path)) { - auto button = m_target->add(entry.path().filename(), this); - } - window()->end_batch(); + // microtasks defer execution of the callback until all external events are processed. + // if they're not used here and update() is called in a click or hover handler, + // chaos will ensue, as the widget tree will be updated during event propagation + window()->queue_microtask([this]() { + target()->clear_children(); + for (const auto &entry : std::filesystem::directory_iterator(m_current_path)) { + auto button = m_target->add(entry.path().filename(), this); + } + }); } void DirectoryView::navigate(std::string path) {