switch to using microtasks for switching, fixing segfaults

This commit is contained in:
hippoz 2022-07-27 02:35:28 +03:00
parent c601beb28e
commit bbec75f451
No known key found for this signature in database
GPG key ID: 7C52899193467641

View file

@ -4,12 +4,15 @@
DirectoryView::~DirectoryView() {} DirectoryView::~DirectoryView() {}
void DirectoryView::update() { void DirectoryView::update() {
window()->start_batch(); // microtasks defer execution of the callback until all external events are processed.
target()->clear_children(); // if they're not used here and update() is called in a click or hover handler,
for (const auto &entry : std::filesystem::directory_iterator(m_current_path)) { // chaos will ensue, as the widget tree will be updated during event propagation
auto button = m_target->add<FileButton>(entry.path().filename(), this); window()->queue_microtask([this]() {
} target()->clear_children();
window()->end_batch(); for (const auto &entry : std::filesystem::directory_iterator(m_current_path)) {
auto button = m_target->add<FileButton>(entry.path().filename(), this);
}
});
} }
void DirectoryView::navigate(std::string path) { void DirectoryView::navigate(std::string path) {