diff --git a/components/detournavigator/asyncnavmeshupdater.cpp b/components/detournavigator/asyncnavmeshupdater.cpp index 7fcfdf98c5..562420955d 100644 --- a/components/detournavigator/asyncnavmeshupdater.cpp +++ b/components/detournavigator/asyncnavmeshupdater.cpp @@ -345,8 +345,12 @@ namespace DetourNavigator while (true) { + bool shouldStop = false; + const auto hasJob = [&] { - return (!mWaiting.empty() && mWaiting.front()->mProcessTime <= std::chrono::steady_clock::now()) + shouldStop = mShouldStop; + return shouldStop + || (!mWaiting.empty() && mWaiting.front()->mProcessTime <= std::chrono::steady_clock::now()) || !threadQueue.empty(); }; @@ -357,6 +361,9 @@ namespace DetourNavigator return mJobs.end(); } + if (shouldStop) + return mJobs.end(); + Log(Debug::Debug) << "Got " << mJobs.size() << " navigator jobs and " << threadQueue.size() << " thread jobs by thread=" << std::this_thread::get_id();