From 641730c4254bf35be3931a3cd9437f1e95669dcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= <sebastien.blin@savoirfairelinux.com> Date: Thu, 28 Oct 2021 16:02:43 -0400 Subject: [PATCH] rendermanager: fix rendering on GNU/Linux use directRenderer storage if libwrap is enabled. Avoid potential crashes by replacing reserve by resize GitLab: #580 Change-Id: I5b8d83a6be2157164b755156bb16a424b38c70ad --- src/rendermanager.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/rendermanager.cpp b/src/rendermanager.cpp index 86cb18873..c483c786c 100644 --- a/src/rendermanager.cpp +++ b/src/rendermanager.cpp @@ -144,24 +144,28 @@ FrameWrapper::slotFrameUpdated(const QString& id) unsigned int width = renderer_->size().width(); unsigned int height = renderer_->size().height(); -#ifndef Q_OS_LINUX - unsigned int size = frame_.storage.size(); - auto imageFormat = QImage::Format_ARGB32_Premultiplied; -#else - unsigned int size = frame_.size; - auto imageFormat = QImage::Format_ARGB32; -#endif + unsigned int size; + QImage::Format imageFormat; + if (renderer_->useDirectRenderer()) { + size = frame_.storage.size(); + imageFormat = QImage::Format_ARGB32_Premultiplied; + } else { + size = frame_.size; + imageFormat = QImage::Format_ARGB32; + } /* * If the frame is empty or not the expected size, * do nothing and keep the last rendered QImage. */ if (size != 0 && size == width * height * 4) { -#ifndef Q_OS_LINUX - buffer_ = std::move(frame_.storage); -#else - buffer_.reserve(size); - std::move(frame_.ptr, frame_.ptr + size, buffer_.begin()); -#endif + if (renderer_->useDirectRenderer()) { + buffer_ = std::move(frame_.storage); + } else { + // TODO remove this path. storage should work everywhere + // https://git.jami.net/savoirfairelinux/jami-libclient/-/issues/492 + buffer_.resize(size); + std::move(frame_.ptr, frame_.ptr + size, buffer_.begin()); + } image_.reset(new QImage((uchar*) buffer_.data(), width, height, imageFormat)); } } -- GitLab