From 3111e6b343009befc9abab07c58da3260c34c7d3 Mon Sep 17 00:00:00 2001 From: m0dB <79429057+m0dB@users.noreply.github.com> Date: Sat, 13 May 2023 12:41:16 +0200 Subject: dont create qopengltexture without valid context or with null images --- src/widget/paintable.cpp | 4 ++++ src/widget/paintable.h | 1 + src/widget/wspinnyglsl.cpp | 42 +++++++++++++++++++++++------------------- src/widget/wvumeterglsl.cpp | 4 ++-- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/widget/paintable.cpp b/src/widget/paintable.cpp index 8968447693..159de34292 100644 --- a/src/widget/paintable.cpp +++ b/src/widget/paintable.cpp @@ -96,6 +96,10 @@ bool Paintable::isNull() const { return m_source.isEmpty(); } +bool Paintable::isPixmapNull() const { + return m_pPixmap.isNull(); +} + QSize Paintable::size() const { if (!m_pPixmap.isNull()) { return m_pPixmap->size(); diff --git a/src/widget/paintable.h b/src/widget/paintable.h index 3dcb185cdf..6d0914006f 100644 --- a/src/widget/paintable.h +++ b/src/widget/paintable.h @@ -46,6 +46,7 @@ class Paintable { void drawCentered(const QRectF& targetRect, QPainter* pPainter, const QRectF& sourceRect); bool isNull() const; + bool isPixmapNull() const; static DrawMode DrawModeFromString(const QString& str); static QString DrawModeToString(DrawMode mode); diff --git a/src/widget/wspinnyglsl.cpp b/src/widget/wspinnyglsl.cpp index 795a2fb6a7..67f8159842 100644 --- a/src/widget/wspinnyglsl.cpp +++ b/src/widget/wspinnyglsl.cpp @@ -27,13 +27,14 @@ void WSpinnyGLSL::cleanupGL() { } void WSpinnyGLSL::coverChanged() { - makeCurrentIfNeeded(); - if (m_loadedCoverScaled.isNull()) { - m_pLoadedCoverTextureScaled.reset(); - } else { - m_pLoadedCoverTextureScaled.reset(new QOpenGLTexture(m_loadedCoverScaled.toImage())); + if (isContextValid()) { + makeCurrentIfNeeded(); + m_pLoadedCoverTextureScaled.reset(!m_loadedCoverScaled.isNull() + ? new QOpenGLTexture(m_loadedCoverScaled.toImage()) + : nullptr); + doneCurrent(); } - doneCurrent(); + // otherwise this will happen in initializeGL } void WSpinnyGLSL::draw() { @@ -112,19 +113,22 @@ void WSpinnyGLSL::paintGL() { } void WSpinnyGLSL::initializeGL() { - if (m_pBgImage && !m_pBgImage->isNull()) - m_pBgTexture.reset(new QOpenGLTexture(*m_pBgImage)); - if (m_pMaskImage && !m_pMaskImage->isNull()) - m_pMaskTexture.reset(new QOpenGLTexture(*m_pMaskImage)); - if (!m_fgImageScaled.isNull()) - m_pFgTextureScaled.reset(new QOpenGLTexture(m_fgImageScaled)); - if (!m_ghostImageScaled.isNull()) - m_pGhostTextureScaled.reset(new QOpenGLTexture(m_ghostImageScaled)); - if (!m_loadedCoverScaled.isNull()) { - m_pLoadedCoverTextureScaled.reset(new QOpenGLTexture(m_loadedCoverScaled.toImage())); - } - if (!m_qImage.isNull()) - m_pQTexture.reset(new QOpenGLTexture(m_qImage)); + m_pBgTexture.reset(m_pBgImage && !m_pBgImage->isNull() + ? new QOpenGLTexture(*m_pBgImage) + : nullptr); + m_pMaskTexture.reset(m_pMaskImage && !m_pMaskImage->isNull() + ? new QOpenGLTexture(*m_pMaskImage) + : nullptr); + m_pFgTextureScaled.reset(!m_fgImageScaled.isNull() + ? new QOpenGLTexture(m_fgImageScaled) + : nullptr); + m_pGhostTextureScaled.reset(!m_ghostImageScaled.isNull() + ? new QOpenGLTexture(m_ghostImageScaled) + : nullptr); + m_pLoadedCoverTextureScaled.reset(!m_loadedCoverScaled.isNull() + ? new QOpenGLTexture(m_loadedCoverScaled.toImage()) + : nullptr); + m_pQTexture.reset(!m_qImage.isNull() ? new QOpenGLTexture(m_qImage) : nullptr); m_textureShader.init(); } diff --git a/src/widget/wvumeterglsl.cpp b/src/widget/wvumeterglsl.cpp index 853d1aa096..20efb02d50 100644 --- a/src/widget/wvumeterglsl.cpp +++ b/src/widget/wvumeterglsl.cpp @@ -20,7 +20,7 @@ void WVuMeterGLSL::draw() { } void WVuMeterGLSL::initializeGL() { - if (m_pPixmapBack.isNull()) { + if (m_pPixmapBack.isNull() || m_pPixmapBack->isPixmapNull()) { m_pTextureBack.reset(); } else { m_pTextureBack.reset(new QOpenGLTexture(m_pPixmapBack->toImage())); @@ -29,7 +29,7 @@ void WVuMeterGLSL::initializeGL() { m_pTextureBack->setWrapMode(QOpenGLTexture::ClampToBorder); } - if (m_pPixmapVu.isNull()) { + if (m_pPixmapVu.isNull() || m_pPixmapVu->isPixmapNull()) { m_pTextureVu.reset(); } else { m_pTextureVu.reset(new QOpenGLTexture(m_pPixmapVu->toImage())); -- cgit v1.2.3