From 8c27e45ef690a58c2aa5241d76f5389ce9659435 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sun, 9 Jun 2024 20:04:45 -0400 Subject: Fixed suspected thread synchronization issue --- src/tracker_state.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/tracker_state.cpp') diff --git a/src/tracker_state.cpp b/src/tracker_state.cpp index 66e7751..a4134f9 100644 --- a/src/tracker_state.cpp +++ b/src/tracker_state.cpp @@ -584,6 +584,8 @@ void ResetReachabilityRequirements() { } void RecalculateReachability() { + std::lock_guard reachability_guard(GetState().reachability_mutex); + StateCalculator state_calculator({.start = GD_GetRoomByName("Menu")}); state_calculator.Calculate(); @@ -616,14 +618,11 @@ void RecalculateReachability() { std::set reachable_paintings = state_calculator.GetReachablePaintings(); std::map> door_reports = state_calculator.GetDoorReports(); - - { - std::lock_guard reachability_guard(GetState().reachability_mutex); - std::swap(GetState().reachability, new_reachability); - std::swap(GetState().reachable_doors, new_reachable_doors); - std::swap(GetState().reachable_paintings, reachable_paintings); - std::swap(GetState().door_reports, door_reports); - } + + std::swap(GetState().reachability, new_reachability); + std::swap(GetState().reachable_doors, new_reachable_doors); + std::swap(GetState().reachable_paintings, reachable_paintings); + std::swap(GetState().door_reports, door_reports); } bool IsLocationReachable(int location_id) { @@ -651,5 +650,5 @@ bool IsPaintingReachable(int painting_id) { const std::map& GetDoorRequirements(int door_id) { std::lock_guard reachability_guard(GetState().reachability_mutex); - return GetState().door_reports[door_id]; + return GetState().door_reports.at(door_id); } -- cgit 1.4.1