From 2870d8d561663b4bad450277d64e19c28e48c641 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Sat, 10 May 2025 09:01:20 -0500 Subject: [PATCH] Fix target-lock V2 crash --- src/game/boe.newgraph.cpp | 5 ++++- src/location.cpp | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/game/boe.newgraph.cpp b/src/game/boe.newgraph.cpp index ea2b7144..4db4c882 100644 --- a/src/game/boe.newgraph.cpp +++ b/src/game/boe.newgraph.cpp @@ -1095,7 +1095,10 @@ void handle_target_mode(eGameMode target_mode, int range, eSpell spell) { } if(!enemy_locs_in_range.empty()){ std::vector dest_candidates = points_containing_most(enemy_locs_in_range, enemy_locs_already_seen); - center = closest_point(dest_candidates, loc); + // Center can stay the same if all points with the most monsters exclude any required (already seen) monsters + if(!dest_candidates.empty()){ + center = closest_point(dest_candidates, loc); + } draw_terrain(); } } diff --git a/src/location.cpp b/src/location.cpp index 7ac2da6c..98f6871a 100644 --- a/src/location.cpp +++ b/src/location.cpp @@ -401,6 +401,8 @@ std::vector points_containing_most(std::vector points, std: } } + if(points_seen_from.empty()) return {}; + // Sort candidates by how many of the points they see std::sort(points_seen_from.begin(), points_seen_from.end(), [](std::pair pair1, std::pair pair2) -> bool { return pair1.second > pair2.second;