From 0706a36ef8ff06370ebcfacb45e7f943147ad304 Mon Sep 17 00:00:00 2001 From: Antoine Lambert Date: Thu, 23 Nov 2023 01:21:02 +0100 Subject: [PATCH] talipot-gui/GlWidget: Fix segfault when not embeded in a graphics item --- library/talipot-gui/include/talipot/GlWidget.h | 6 +++++- library/talipot-gui/src/GlWidget.cpp | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/library/talipot-gui/include/talipot/GlWidget.h b/library/talipot-gui/include/talipot/GlWidget.h index 93bd69f90a..4689354d80 100644 --- a/library/talipot-gui/include/talipot/GlWidget.h +++ b/library/talipot-gui/include/talipot/GlWidget.h @@ -286,7 +286,11 @@ class TLP_QT_SCOPE GlWidget : public QOpenGLWidget { // devicePixelRatio() must be overridden because the inherited QWidget // method always returns 1 when the widget is no attached to a window qreal devicePixelRatio() const { - return _windows->devicePixelRatio(); + if (_windows) { + return _windows->devicePixelRatio(); + } else { + return QOpenGLWidget::devicePixelRatio(); + } } private: diff --git a/library/talipot-gui/src/GlWidget.cpp b/library/talipot-gui/src/GlWidget.cpp index ec10d31d31..22d1395e1d 100644 --- a/library/talipot-gui/src/GlWidget.cpp +++ b/library/talipot-gui/src/GlWidget.cpp @@ -69,7 +69,7 @@ GlWidget::GlWidget(QWidget *parent, View *view) // windows attached to it, making device pixel ratio value unreliable so we // grab a pointer to the adequate main window to override the implementation // of the devicePixelRatio method - _windows = window()->windowHandle() ? window() : getMainWindow(); + _windows = window()->windowHandle() ? nullptr : getMainWindow(); } //================================================== GlWidget::~GlWidget() {