diff --git a/src/services/gta_data/gta_data_service.cpp b/src/services/gta_data/gta_data_service.cpp index 925b3ed7..ed99eeea 100644 --- a/src/services/gta_data/gta_data_service.cpp +++ b/src/services/gta_data/gta_data_service.cpp @@ -271,19 +271,26 @@ namespace big void gta_data_service::rebuild_cache() { + static bool completed = false; + + if (completed == true) + { + return; + } + using hash_array = std::vector; - hash_array mapped_peds; - hash_array mapped_vehicles; - hash_array mapped_weapons; - hash_array mapped_components; + hash_array mapped_peds{}; + hash_array mapped_vehicles{}; + hash_array mapped_weapons{}; + hash_array mapped_components{}; int mp_weapons_thread_id = 0; - std::vector peds; - std::vector vehicles; + std::vector peds{}; + std::vector vehicles{}; //std::vector weapons; - std::unordered_map weapons; - std::vector weapon_components; + std::unordered_map weapons{}; + std::vector weapon_components{}; constexpr auto exists = [](const hash_array& arr, uint32_t val) -> bool { return std::find(arr.begin(), arr.end(), val) != arr.end(); @@ -675,6 +682,8 @@ namespace big LOG(INFO) << "Finished writing cache to disk."; load_data(); + + completed = true; //Prevent repeat calls. }); } } diff --git a/src/views/settings/view_gta_cache.cpp b/src/views/settings/view_gta_cache.cpp index edcd7911..ceeae457 100644 --- a/src/views/settings/view_gta_cache.cpp +++ b/src/views/settings/view_gta_cache.cpp @@ -13,7 +13,7 @@ namespace big ImGui::Text(std::format("{}: {}\n{}: {}\n{}: {}\n{}: {}", "VIEW_GTA_CACHE_PEDS_CACHED"_T, ped_count, "VIEW_GTA_CACHE_VEHICLES_CACHED"_T, veh_count, "VIEW_GTA_CACHE_WEAPONS_CACHED"_T, wep_count, "VIEW_GTA_CACHE_WEAPON_COMPONENTS_CACHED"_T, wep_comp_count) .c_str()); - if (components::button("VIEW_GTA_CACHE_REBUILD_CACHE"_T)) + if (!*g_pointers->m_gta.m_is_session_started && components::button("VIEW_GTA_CACHE_REBUILD_CACHE"_T)) { g_gta_data_service.set_state(eGtaDataUpdateState::NEEDS_UPDATE); g_gta_data_service.update_now();