From ee7f4c47b26a6dd1e7e56b65ab0633c11023c40c Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Fri, 23 Dec 2022 04:41:04 +0100 Subject: [PATCH] screencast: Do not attempt to render an empty cursor This will make the system assert upon bind as the image is null and thus never allocated. --- src/plugins/screencast/screencaststream.cpp | 57 +++++++++++---------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/src/plugins/screencast/screencaststream.cpp b/src/plugins/screencast/screencaststream.cpp index 42651bcbb1..0fb0989871 100644 --- a/src/plugins/screencast/screencaststream.cpp +++ b/src/plugins/screencast/screencaststream.cpp @@ -465,36 +465,41 @@ void ScreenCastStream::recordFrame(const QRegion &_damagedRegion) auto cursor = Cursors::self()->currentCursor(); if (m_cursor.mode == KWaylandServer::ScreencastV1Interface::Embedded && m_cursor.viewport.contains(cursor->pos())) { - GLFramebuffer::pushFramebuffer(buf->framebuffer()); + if (!cursor->image().isNull()) { + GLFramebuffer::pushFramebuffer(buf->framebuffer()); - QRect r(QPoint(), size); - auto shader = ShaderManager::instance()->pushShader(ShaderTrait::MapTexture); + QRect r(QPoint(), size); + auto shader = ShaderManager::instance()->pushShader(ShaderTrait::MapTexture); - QMatrix4x4 mvp; - mvp.ortho(r); - shader->setUniform(GLShader::ModelViewProjectionMatrix, mvp); + QMatrix4x4 mvp; + mvp.ortho(r); + shader->setUniform(GLShader::ModelViewProjectionMatrix, mvp); - if (!m_cursor.texture || m_cursor.lastKey != cursor->image().cacheKey()) { - m_cursor.texture.reset(new GLTexture(cursor->image())); + if (!m_cursor.texture || m_cursor.lastKey != cursor->image().cacheKey()) { + m_cursor.texture.reset(new GLTexture(cursor->image())); + } + + m_cursor.texture->setYInverted(false); + m_cursor.texture->bind(); + const auto cursorRect = cursorGeometry(cursor); + mvp.translate(cursorRect.left(), r.height() - cursorRect.top() - cursor->image().height()); + shader->setUniform(GLShader::ModelViewProjectionMatrix, mvp); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + m_cursor.texture->render(cursorRect, m_cursor.scale); + glDisable(GL_BLEND); + m_cursor.texture->unbind(); + + ShaderManager::instance()->popShader(); + GLFramebuffer::popFramebuffer(); + + damagedRegion += QRegion{m_cursor.lastRect} | cursorRect; + m_cursor.lastRect = cursorRect; + } else { + damagedRegion |= m_cursor.lastRect; + m_cursor.lastRect = {}; } - - m_cursor.texture->setYInverted(false); - m_cursor.texture->bind(); - const auto cursorRect = cursorGeometry(cursor); - mvp.translate(cursorRect.left(), r.height() - cursorRect.top() - cursor->image().height()); - shader->setUniform(GLShader::ModelViewProjectionMatrix, mvp); - - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - m_cursor.texture->render(cursorRect, m_cursor.scale); - glDisable(GL_BLEND); - m_cursor.texture->unbind(); - - ShaderManager::instance()->popShader(); - GLFramebuffer::popFramebuffer(); - - damagedRegion += QRegion{m_cursor.lastRect} | cursorRect; - m_cursor.lastRect = cursorRect; } }