From 5512437f1bd5b2be7997b52bf36b04930446f3f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82?= Date: Sun, 6 Jun 2021 21:59:53 +0200 Subject: [PATCH] Fixed a crash introduced in 2f568b8 (#2856) (#2871) --- src/providers/IvrApi.cpp | 2 -- src/providers/twitch/TwitchAccount.cpp | 9 ++++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/providers/IvrApi.cpp b/src/providers/IvrApi.cpp index 4c042d71..3e5ac4dd 100644 --- a/src/providers/IvrApi.cpp +++ b/src/providers/IvrApi.cpp @@ -37,8 +37,6 @@ void IvrApi::getBulkEmoteSets(QString emoteSetList, ResultCallback successCallback, IvrFailureCallback failureCallback) { - assert(!emoteSetList.isEmpty()); - QUrlQuery urlQuery; urlQuery.addQueryItem("set_id", emoteSetList); diff --git a/src/providers/twitch/TwitchAccount.cpp b/src/providers/twitch/TwitchAccount.cpp index e98707cc..495b9502 100644 --- a/src/providers/twitch/TwitchAccount.cpp +++ b/src/providers/twitch/TwitchAccount.cpp @@ -307,13 +307,16 @@ void TwitchAccount::loadUserstateEmotes(QStringList emoteSetKeys) constexpr int batchSize = 100; std::vector batches; + int batchCount = (newEmoteSetKeys.size() / batchSize) + 1; - batches.reserve((newEmoteSetKeys.size() + 1) / batchSize); + batches.reserve(batchCount); - for (int i = 0; i < newEmoteSetKeys.size(); i += batchSize) + for (int i = 0; i < batchCount; i++) { QStringList batch; - for (int j = batchSize * i; j < batchSize; j++) + + int last = std::min(batchSize, newEmoteSetKeys.size() - batchSize * i); + for (int j = batchSize * i; j < last; j++) { batch.push_back(newEmoteSetKeys.at(j)); }