diff --git a/src/core/libraries/np_trophy/trophy_ui.cpp b/src/core/libraries/np_trophy/trophy_ui.cpp index 14d1b6b5e..f503b9d94 100644 --- a/src/core/libraries/np_trophy/trophy_ui.cpp +++ b/src/core/libraries/np_trophy/trophy_ui.cpp @@ -6,6 +6,7 @@ #include "common/assert.h" #include "common/singleton.h" #include "imgui/imgui_std.h" +#include #include "trophy_ui.h" using namespace ImGui; @@ -13,13 +14,14 @@ namespace Libraries::NpTrophy { std::optional current_trophy_ui; std::queue trophy_queue; +std::mutex queueMtx; TrophyUI::TrophyUI(std::filesystem::path trophyIconPath, std::string trophyName) - : trophy_icon_path(trophyIconPath), trophy_name(trophyName) { - if (std::filesystem::exists(trophy_icon_path)) { - trophy_icon = RefCountedTexture::DecodePngFile(trophy_icon_path); + : trophy_name(trophyName) { + if (std::filesystem::exists(trophyIconPath)) { + trophy_icon = RefCountedTexture::DecodePngFile(trophyIconPath); } else { - LOG_ERROR(Lib_NpTrophy, "Couldnt load trophy icon at {}", trophy_icon_path.string()); + LOG_ERROR(Lib_NpTrophy, "Couldnt load trophy icon at {}", trophyIconPath.string()); } AddLayer(this); } @@ -64,6 +66,7 @@ void TrophyUI::Draw() { trophy_timer -= io.DeltaTime; if (trophy_timer <= 0) { + queueMtx.lock(); if (!trophy_queue.empty()) { TrophyInfo next_trophy = trophy_queue.front(); trophy_queue.pop(); @@ -71,10 +74,12 @@ void TrophyUI::Draw() { } else { current_trophy_ui.reset(); } + queueMtx.unlock(); } } void AddTrophyToQueue(std::filesystem::path trophyIconPath, std::string trophyName) { + queueMtx.lock(); if (current_trophy_ui.has_value()) { TrophyInfo new_trophy; new_trophy.trophy_icon_path = trophyIconPath; @@ -83,6 +88,7 @@ void AddTrophyToQueue(std::filesystem::path trophyIconPath, std::string trophyNa } else { current_trophy_ui.emplace(trophyIconPath, trophyName); } + queueMtx.unlock(); } } // namespace Libraries::NpTrophy \ No newline at end of file diff --git a/src/core/libraries/np_trophy/trophy_ui.h b/src/core/libraries/np_trophy/trophy_ui.h index fb7f914d2..4448c2281 100644 --- a/src/core/libraries/np_trophy/trophy_ui.h +++ b/src/core/libraries/np_trophy/trophy_ui.h @@ -25,7 +25,6 @@ public: void Draw() override; private: - std::filesystem::path trophy_icon_path; std::string trophy_name; float trophy_timer = 5.0f; ImGui::RefCountedTexture trophy_icon;