diff --git a/lib/appbase/debug/AssertInGuiThread.hpp b/lib/appbase/debug/AssertInGuiThread.hpp index 707aa8046..a9ba41fcf 100644 --- a/lib/appbase/debug/AssertInGuiThread.hpp +++ b/lib/appbase/debug/AssertInGuiThread.hpp @@ -6,10 +6,15 @@ namespace AB_NAMESPACE { +static bool isGuiThread() +{ + return QCoreApplication::instance()->thread() == QThread::currentThread(); +} + static void assertInGuiThread() { #ifdef _DEBUG - assert(QCoreApplication::instance()->thread() == QThread::currentThread()); + assert(isGuiThread()); #endif } diff --git a/src/common/SignalVector.hpp b/src/common/SignalVector.hpp index db03df265..c0b0af0eb 100644 --- a/src/common/SignalVector.hpp +++ b/src/common/SignalVector.hpp @@ -40,6 +40,14 @@ public: { } + Iterator &operator=(const Iterator &other) + { + this->lock_ = std::shared_lock(other.mutex_.get()); + this->mutex_ = other.mutex_; + + return *this; + } + TVectorItem &operator*() { return it_.operator*(); @@ -69,7 +77,7 @@ public: private: VecIt it_; std::shared_lock lock_; - std::shared_mutex &mutex_; + std::reference_wrapper mutex_; }; ReadOnlySignalVector() @@ -113,6 +121,13 @@ public: return this->vector_; } + const std::vector cloneVector() const + { + std::shared_lock lock(this->mutex_); + + return this->vector_; + } + void invokeDelayedItemsChanged() { assertInGuiThread(); diff --git a/src/messages/Image.cpp b/src/messages/Image.cpp index b5cc3265b..7d397be29 100644 --- a/src/messages/Image.cpp +++ b/src/messages/Image.cpp @@ -221,7 +221,11 @@ ImagePtr Image::fromUrl(const Url &url, qreal scale) ImagePtr Image::fromPixmap(const QPixmap &pixmap, qreal scale) { - return ImagePtr(new Image(pixmap, scale)); + auto result = ImagePtr(new Image(scale)); + + result->setPixmap(pixmap); + + return result; } ImagePtr Image::getEmpty() @@ -243,13 +247,29 @@ Image::Image(const Url &url, qreal scale) { } -Image::Image(const QPixmap &pixmap, qreal scale) +Image::Image(qreal scale) : scale_(scale) - , frames_(std::make_unique( - QVector>{detail::Frame{pixmap, 1}})) + , frames_(std::make_unique()) { } +void Image::setPixmap(const QPixmap &pixmap) +{ + auto setFrames = [shared = this->shared_from_this(), pixmap]() { + shared->frames_ = std::make_unique( + QVector>{detail::Frame{pixmap, 1}}); + }; + + if (isGuiThread()) + { + setFrames(); + } + else + { + postToThread(setFrames); + } +} + const Url &Image::url() const { return this->url_; diff --git a/src/messages/Image.hpp b/src/messages/Image.hpp index f5840de63..8db607e42 100644 --- a/src/messages/Image.hpp +++ b/src/messages/Image.hpp @@ -66,7 +66,9 @@ public: private: Image(); Image(const Url &url, qreal scale); - Image(const QPixmap &nonOwning, qreal scale); + Image(qreal scale); + + void setPixmap(const QPixmap &pixmap); void load(); diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 0ff3e74e2..884e7abe4 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -796,19 +796,19 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg) ? QUrl::fromLocalFile(getSettings()->pathHighlightSound.getValue()) : QUrl("qrc:/sounds/ping2.wav"); - if (currentPlayerUrl != highlightSoundUrl) - { - player->setMedia(highlightSoundUrl); + // if (currentPlayerUrl != highlightSoundUrl) + // { + // player->setMedia(highlightSoundUrl); - currentPlayerUrl = highlightSoundUrl; - } + // currentPlayerUrl = highlightSoundUrl; + // } // TODO: This vector should only be rebuilt upon highlights being changed // fourtf: should be implemented in the HighlightsController std::vector activeHighlights = - app->highlights->phrases.getVector(); + app->highlights->phrases.cloneVector(); std::vector userHighlights = - app->highlights->highlightedUsers.getVector(); + app->highlights->highlightedUsers.cloneVector(); if (getSettings()->enableSelfHighlight && currentUsername.size() > 0) {