From e91184ec8293945c531082f3e7c1db32289f516a Mon Sep 17 00:00:00 2001 From: Patrick Wuttke Date: Sat, 30 Aug 2025 00:25:16 +0200 Subject: [PATCH] Fixed current loop not being reset on exceptions. --- source/mijin/async/coroutine.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/mijin/async/coroutine.hpp b/source/mijin/async/coroutine.hpp index f9d2eee..a846ce3 100644 --- a/source/mijin/async/coroutine.hpp +++ b/source/mijin/async/coroutine.hpp @@ -25,6 +25,7 @@ #include "../util/flag.hpp" #include "../util/iterators.hpp" #include "../util/misc.hpp" +#include "../util/scope_guard.hpp" #include "../util/traits.hpp" #if MIJIN_COROUTINE_ENABLE_DEBUG_INFO #include "../debug/stacktrace.hpp" @@ -997,6 +998,9 @@ inline auto BaseSimpleTaskLoop::tick() -> CanContinue // set current taskloop MIJIN_ASSERT(TaskLoop::currentLoopStorage() == nullptr, "Trying to tick a loop from a coroutine, this is not supported."); TaskLoop::currentLoopStorage() = this; + MIJIN_SCOPE_EXIT { + TaskLoop::currentLoopStorage() = nullptr; + }; threadId_ = std::this_thread::get_id(); // move over all tasks from newTasks @@ -1046,8 +1050,6 @@ inline auto BaseSimpleTaskLoop::tick() -> CanContinue canContinue = CanContinue::YES; } } - // reset current loop - TaskLoop::currentLoopStorage() = nullptr; // remove any tasks that have been transferred to another queue it = std::remove_if(tasks_.begin(), tasks_.end(), [](const StoredTask& task) {