Browse Source

common: fiber: YieldTo: Avoid hard crash on nullptr previous_fiber.

- When the emulator crashes to desktop below, we don't even get this captured in a log, making such issues harder to debug.
bunnei 4 years ago
parent
commit
f6de57c1a5
1 changed files with 4 additions and 1 deletions
  1. 4 1
      src/common/fiber.cpp

+ 4 - 1
src/common/fiber.cpp

@@ -124,7 +124,10 @@ void Fiber::YieldTo(std::weak_ptr<Fiber> weak_from, Fiber& to) {
 
 
     // "from" might no longer be valid if the thread was killed
     // "from" might no longer be valid if the thread was killed
     if (auto from = weak_from.lock()) {
     if (auto from = weak_from.lock()) {
-        ASSERT(from->impl->previous_fiber != nullptr);
+        if (from->impl->previous_fiber == nullptr) {
+            ASSERT_MSG(false, "previous_fiber is nullptr!");
+            return;
+        }
         from->impl->previous_fiber->impl->context = transfer.fctx;
         from->impl->previous_fiber->impl->context = transfer.fctx;
         from->impl->previous_fiber->impl->guard.unlock();
         from->impl->previous_fiber->impl->guard.unlock();
         from->impl->previous_fiber.reset();
         from->impl->previous_fiber.reset();