From 6d38bfec8c1238f94a0fcbad734c84fa77b879fe Mon Sep 17 00:00:00 2001 From: Alayan <25536748+Alayan-stk-2@users.noreply.github.com> Date: Wed, 6 Dec 2023 19:57:29 +0100 Subject: [PATCH] Fix 'Replay with UID of lu' error - Correctly format the log to display the actual UID - Fix getReplaydIdByUid being called with an UID of 0, when no replay to compare has been selected --- src/replay/replay_play.cpp | 4 ++-- src/states_screens/ghost_replay_selection.cpp | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/replay/replay_play.cpp b/src/replay/replay_play.cpp index 64b56bc99a7..adb95709695 100644 --- a/src/replay/replay_play.cpp +++ b/src/replay/replay_play.cpp @@ -543,6 +543,6 @@ unsigned int ReplayPlay::getReplayIdByUID(uint64_t uid) } } - Log::error("Replay", "Replay with UID of " PRIu64 " not found.", uid); + Log::error("Replay", "Replay with UID of %" PRIu64 " not found.", uid); return 0; -} //setReplayFileByUID +} //getReplayIdByUID diff --git a/src/states_screens/ghost_replay_selection.cpp b/src/states_screens/ghost_replay_selection.cpp index 104467b02a3..6da76a686d8 100644 --- a/src/states_screens/ghost_replay_selection.cpp +++ b/src/states_screens/ghost_replay_selection.cpp @@ -294,10 +294,15 @@ void GhostReplaySelection::loadList() unsigned int best_index = 0; - // getReplayIdByUID will send 0 if the UID is incorrect, - // and m_is_comparing will be false if it is incorrect, - // so it always work - unsigned int compare_index = ReplayPlay::get()->getReplayIdByUID(m_replay_to_compare_uid); + // Only compute the compare index if we are actually going to compare. + // This avoids spurious errors trying to find a replay with UID 0. + unsigned int compare_index = 0; + if (m_is_comparing) + // In case the requested replay is not found, compare_index will be 0. + compare_index = ReplayPlay::get()->getReplayIdByUID(m_replay_to_compare_uid); + + // It's better to do this when not comparing than to do it repeatedly in the loop, + // it will simply be unused if not comparing. const ReplayPlay::ReplayData& rd_compare = ReplayPlay::get()->getReplayData(compare_index); for (unsigned int i = 0; i < ReplayPlay::get()->getNumReplayFile() ; i++)