From b4702eb632be23870b89d46c50f6f2941248020e Mon Sep 17 00:00:00 2001 From: mostlikely4r Date: Fri, 9 Feb 2024 23:01:44 +0100 Subject: [PATCH] -Crash fix: When looking at random-teleport locations beyond 200000 yards. --- playerbot/TravelMgr.cpp | 11 +++++++++++ playerbot/TravelMgr.h | 8 -------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/playerbot/TravelMgr.cpp b/playerbot/TravelMgr.cpp index e0af7a544..2379c3300 100644 --- a/playerbot/TravelMgr.cpp +++ b/playerbot/TravelMgr.cpp @@ -2568,6 +2568,17 @@ vector TravelMgr::getNextPoint(WorldPosition* center, vectordistance(*center)); }); + //If any weight is 0 add 1 to all weights. + for (auto& w : weights) + { + if (w > 0) + continue; + + std::for_each(weights.begin(), weights.end(), [](uint32& d) { d += 1; }); + break; + + } + std::mt19937 gen(time(0)); weighted_shuffle(retVec.begin(), retVec.end(), weights.begin(), weights.end(), gen); diff --git a/playerbot/TravelMgr.h b/playerbot/TravelMgr.h index 16fc55a18..5ec90019d 100644 --- a/playerbot/TravelMgr.h +++ b/playerbot/TravelMgr.h @@ -358,14 +358,6 @@ namespace ai , W first_weight, W last_weight , URBG&& g) { - //Only shuffle if there is atleast 1 non-zero value. - W check_weight = first_weight; - while (check_weight != last_weight && !*check_weight) - ++check_weight; - - if (check_weight == last_weight) - return; - while (first != last && first_weight != last_weight) { std::discrete_distribution dd(first_weight, last_weight);