Skip to content

Commit

Permalink
Fix using GL texture IDs that may be released.
Browse files Browse the repository at this point in the history
This problem occurred in GPU processing mode. With NVIDIA/Linux
OpenGL Threaded Optimizations, it would cause frames to sometimes
display out-of-order (reported by Ochi on GitHub). It could have
been a problem on other platforms and drivers as well in theory.
  • Loading branch information
ddennedy committed Aug 8, 2017
1 parent 60cba7f commit 4d4dfbf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
1 change: 0 additions & 1 deletion scripts/build-shotcut.sh
Expand Up @@ -2065,7 +2065,6 @@ export MLT_DATA="\$INSTALL_DIR/share/mlt"
export MLT_PROFILES_PATH="\$INSTALL_DIR/share/mlt/profiles"
export FREI0R_PATH="\$INSTALL_DIR/lib/frei0r-1"
export MLT_MOVIT_PATH="\$INSTALL_DIR/share/movit"
export __GL_THREADED_OPTIMIZATIONS=0
cd "\$INSTALL_DIR"
export QT_PLUGIN_PATH="lib/qt5"
export QML2_IMPORT_PATH="lib/qml"
Expand Down
31 changes: 21 additions & 10 deletions src/glwidget.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2016 Meltytech, LLC
* Copyright (c) 2011-2017 Meltytech, LLC
* Author: Dan Dennedy <dan@dennedy.org>
*
* GL shader based on BSD licensed code from Peter Bengtsson:
Expand Down Expand Up @@ -173,10 +173,8 @@ void GLWidget::initializeGL()
quickWindow()->openglContext()->makeCurrent(quickWindow());

connect(m_frameRenderer, SIGNAL(frameDisplayed(const SharedFrame&)), this, SIGNAL(frameDisplayed(const SharedFrame&)), Qt::QueuedConnection);
if (Settings.playerGPU() || quickWindow()->openglContext()->supportsThreadedOpenGL())
connect(m_frameRenderer, SIGNAL(textureReady(GLuint,GLuint,GLuint)), SLOT(updateTexture(GLuint,GLuint,GLuint)), Qt::DirectConnection);
else
connect(m_frameRenderer, SIGNAL(frameDisplayed(const SharedFrame&)), SLOT(onFrameDisplayed(const SharedFrame&)), Qt::QueuedConnection);
connect(m_frameRenderer, SIGNAL(textureReady(GLuint,GLuint,GLuint)), SLOT(updateTexture(GLuint,GLuint,GLuint)), Qt::DirectConnection);
connect(m_frameRenderer, SIGNAL(frameDisplayed(const SharedFrame&)), SLOT(onFrameDisplayed(const SharedFrame&)), Qt::QueuedConnection);
connect(m_frameRenderer, SIGNAL(imageReady()), SIGNAL(imageReady()));

m_initSem.release();
Expand Down Expand Up @@ -366,9 +364,18 @@ void GLWidget::paintGL()
}
uploadTextures(quickWindow()->openglContext(), m_sharedFrame, m_texture);
m_mutex.unlock();
} else if (m_glslManager) {
m_mutex.lock();
if (m_sharedFrame.is_valid()) {
m_texture[0] = *((GLuint*) m_sharedFrame.get_image());
}
}

if (!m_texture[0]) return;
if (!m_texture[0]) {
if (m_glslManager)
m_mutex.unlock();
return;
}

// Bind textures.
for (int i = 0; i < 3; ++i) {
Expand Down Expand Up @@ -449,6 +456,11 @@ void GLWidget::paintGL()
}
glActiveTexture(GL_TEXTURE0);
check_error(f);

if (m_glslManager) {
glFinish(); check_error(f);
m_mutex.unlock();
}
}

void GLWidget::mousePressEvent(QMouseEvent* event)
Expand Down Expand Up @@ -896,13 +908,12 @@ void FrameRenderer::showFrame(Mlt::Frame frame)
mlt_pool_release(image);
emit imageReady();
}

emit textureReady(*textureId);

m_context->doneCurrent();

// Save this frame for future use and to keep a reference to the GL Texture.
m_renderFrame = SharedFrame(frame);
qSwap(m_renderFrame, m_displayFrame);
m_displayFrame = SharedFrame(frame);
emit frameDisplayed(m_displayFrame);
}
else {
// Using a threaded OpenGL to upload textures.
Expand Down
3 changes: 1 addition & 2 deletions src/glwidget.h
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2015 Meltytech, LLC
* Copyright (c) 2011-2017 Meltytech, LLC
* Author: Dan Dennedy <dan@dennedy.org>
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -188,7 +188,6 @@ public slots:

private:
QSemaphore m_semaphore;
SharedFrame m_renderFrame;
SharedFrame m_displayFrame;
QOpenGLContext* m_context;
QSurface* m_surface;
Expand Down

0 comments on commit 4d4dfbf

Please sign in to comment.