From a10dd4f7f71080e875a235e46d633151766175e7 Mon Sep 17 00:00:00 2001 From: Mysticial Date: Sat, 23 Mar 2024 11:48:52 -0700 Subject: [PATCH] Fix crash when webhook throttling is set to zero. --- SerialPrograms/Source/Integrations/DiscordWebhook.cpp | 4 ++-- .../Framework/NintendoSwitch_SwitchSystemOption.cpp | 2 +- .../Programs/General/PokemonSV_StatsResetEventBattle.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/SerialPrograms/Source/Integrations/DiscordWebhook.cpp b/SerialPrograms/Source/Integrations/DiscordWebhook.cpp index 591ac7352..3451a49fb 100644 --- a/SerialPrograms/Source/Integrations/DiscordWebhook.cpp +++ b/SerialPrograms/Source/Integrations/DiscordWebhook.cpp @@ -113,12 +113,12 @@ void DiscordWebhookSender::throttle(){ while (!m_sent.empty() && m_sent[0] + duration < now){ m_sent.pop_front(); } - if (m_sent.size() >= GlobalSettings::instance().DISCORD.webhooks.sends_per_second){ + if (!m_sent.empty() && m_sent.size() >= GlobalSettings::instance().DISCORD.webhooks.sends_per_second){ m_logger.log("Throttling webhook messages due to rate limit...", COLOR_RED); std::unique_lock lg(m_lock); m_cv.wait_for( lg, duration, - [&]{ return m_sent[0] + duration < now || m_stopping; } + [&]{ return m_stopping || m_sent.empty() || m_sent[0] + duration < now; } ); if (m_stopping){ return; diff --git a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SwitchSystemOption.cpp b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SwitchSystemOption.cpp index 1420455d6..3e8d71aea 100644 --- a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SwitchSystemOption.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SwitchSystemOption.cpp @@ -8,7 +8,7 @@ #include "Common/Cpp/Json/JsonObject.h" #include "NintendoSwitch/NintendoSwitch_Settings.h" #include "NintendoSwitch_SwitchSystemOption.h" -#include "UI/NintendoSwitch_SwitchSystemWidget.h" +//#include "UI/NintendoSwitch_SwitchSystemWidget.h" namespace PokemonAutomation{ namespace NintendoSwitch{ diff --git a/SerialPrograms/Source/PokemonSV/Programs/General/PokemonSV_StatsResetEventBattle.cpp b/SerialPrograms/Source/PokemonSV/Programs/General/PokemonSV_StatsResetEventBattle.cpp index fdb358e55..b40478342 100644 --- a/SerialPrograms/Source/PokemonSV/Programs/General/PokemonSV_StatsResetEventBattle.cpp +++ b/SerialPrograms/Source/PokemonSV/Programs/General/PokemonSV_StatsResetEventBattle.cpp @@ -621,10 +621,10 @@ void StatsResetEventBattle::program(SingleSwitchProgramEnvironment& env, BotBase while (true){ if (TARGET == Target::Ursaluna) { enter_battle_ursaluna(env, context); - } else { + }else{ enter_battle_pecharunt(env, context); } - + if (run_battle(env, context) && check_stats_after_win(env, context)){ break; }