From 33db006635c85ed92fa67c2d25c7e25ec02e3ca6 Mon Sep 17 00:00:00 2001 From: Daniel Sage <24928223+dnsge@users.noreply.github.com> Date: Sat, 20 Aug 2022 05:01:16 -0400 Subject: [PATCH] Fix crash when adding recent messages to empty Channel (#3932) * Fix crash when adding recent messages to empty Channel * Update CHANGELOG.md --- CHANGELOG.md | 2 +- src/common/Channel.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61c9df0d4..58636f507 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,7 +26,7 @@ - Minor: Removed total views from the usercard, as Twitch no longer updates the number. (#3792) - Minor: Add Quick Switcher item to open a channel in a new popup window. (#3828) - Minor: Warn when parsing an environment variable fails. (#3904) -- Minor: Load missing messages from Recent Messages API upon reconnecting (#3878) +- Minor: Load missing messages from Recent Messages API upon reconnecting (#3878, #3932) - Bugfix: Fix crash that can occur when closing and quickly reopening a split, then running a command. (#3852) - Bugfix: Connection to Twitch PubSub now recovers more reliably. (#3643, #3716) - Bugfix: Fix crash that can occur when changing channels. (#3799) diff --git a/src/common/Channel.cpp b/src/common/Channel.cpp index 68cc29874..e47362572 100644 --- a/src/common/Channel.cpp +++ b/src/common/Channel.cpp @@ -237,7 +237,20 @@ void Channel::addMessagesAtStart(const std::vector &_messages) void Channel::fillInMissingMessages(const std::vector &messages) { + if (messages.empty()) + { + return; + } + auto snapshot = this->getMessageSnapshot(); + if (snapshot.size() == 0) + { + // There are no messages in this channel yet so we can just insert them + // at the front in order + this->messages_.pushFront(messages); + this->filledInMessages.invoke(messages); + return; + } std::unordered_set existingMessageIds; existingMessageIds.reserve(snapshot.size());