From 053ea1039384cee195ba4510e2845867b2cbe8bc Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sun, 22 Mar 2020 20:09:05 +1100 Subject: [PATCH] viewer: fixed occasional segfault when setting the viewer node Since other parts of the UI use OpenGL (through Qt), the viewer's context can sometimes become non-current until the next time it draws. Since the color processor is created before the main drawing function, the context could occasionally be non-current causing its creation to fail. Subsequently trying to use that color processor would trigger a segfault. This commit addresses that by always making the context current before creating the color processor shader. --- app/widget/viewer/viewerglwidget.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/app/widget/viewer/viewerglwidget.cpp b/app/widget/viewer/viewerglwidget.cpp index ccd5ed595..d89125d55 100644 --- a/app/widget/viewer/viewerglwidget.cpp +++ b/app/widget/viewer/viewerglwidget.cpp @@ -51,14 +51,18 @@ ViewerGLWidget::~ViewerGLWidget() void ViewerGLWidget::ConnectColorManager(ColorManager *color_manager) { + if (color_manager_ == color_manager) { + return; + } + if (color_manager_ != nullptr) { - disconnect(color_manager_, SIGNAL(ConfigChanged()), this, SLOT(RefreshColorPipeline())); + disconnect(color_manager_, &ColorManager::ConfigChanged, this, &ViewerGLWidget::RefreshColorPipeline); } color_manager_ = color_manager; if (color_manager_ != nullptr) { - connect(color_manager_, SIGNAL(ConfigChanged()), this, SLOT(RefreshColorPipeline())); + connect(color_manager_, &ColorManager::ConfigChanged, this, &ViewerGLWidget::RefreshColorPipeline); } RefreshColorPipeline(); @@ -195,7 +199,7 @@ void ViewerGLWidget::initializeGL() { SetupColorProcessor(); - connect(context(), SIGNAL(aboutToBeDestroyed()), this, SLOT(ContextCleanup()), Qt::DirectConnection); + connect(context(), &QOpenGLContext::aboutToBeDestroyed, this, &ViewerGLWidget::ContextCleanup, Qt::DirectConnection); #ifdef Q_OS_LINUX if (!nouveau_check_done_) { @@ -287,25 +291,24 @@ void ViewerGLWidget::SetupColorProcessor() // (Re)create color processor try { - ColorProcessorPtr new_service = ColorProcessor::Create(color_manager_->GetConfig(), - OCIO::ROLE_SCENE_LINEAR, - ocio_display_, - ocio_view_, - ocio_look_); color_service_ = OpenGLColorProcessor::Create(color_manager_->GetConfig(), - OCIO::ROLE_SCENE_LINEAR, - ocio_display_, - ocio_view_, - ocio_look_); + OCIO::ROLE_SCENE_LINEAR, + ocio_display_, + ocio_view_, + ocio_look_); + makeCurrent(); color_service_->Enable(context(), true); + doneCurrent(); } catch (OCIO::Exception& e) { + QMessageBox::critical(this, tr("OpenColorIO Error"), tr("Failed to set color configuration: %1").arg(e.what()), QMessageBox::Ok); + } } else {