Add nullptr guard to QHighDScaling::scaleAndOrigin(QPlatformScreen *)
Commit b6ded193
added an unconditional dereference
of the platformScreen pointer, for calls where nativePostion
is non-nullptr.
Change-Id: I4a6fbbd0337f91d4fcb76c17b4dc60e1b9ad10ed
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
a08ac1986d
commit
5d7f113320
@ -456,6 +456,8 @@ QHighDpiScaling::ScaleAndOrigin QHighDpiScaling::scaleAndOrigin(const QPlatformS
|
||||
{
|
||||
if (!m_active)
|
||||
return { qreal(1), QPoint() };
|
||||
if (!platformScreen)
|
||||
return { m_factor, QPoint() }; // the global factor
|
||||
const QPlatformScreen *actualScreen = nativePosition ?
|
||||
platformScreen->screenForPosition(*nativePosition) : platformScreen;
|
||||
return { m_factor * screenSubfactor(actualScreen), actualScreen->geometry().topLeft() };
|
||||
|
@ -36,6 +36,7 @@ class tst_QHighDpiScaling: public QObject
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void factor();
|
||||
void scale();
|
||||
};
|
||||
|
||||
@ -50,6 +51,23 @@ public:
|
||||
QImage::Format format() const override { return QImage::Format_ARGB32_Premultiplied; }
|
||||
};
|
||||
|
||||
void tst_QHighDpiScaling::factor()
|
||||
{
|
||||
QHighDpiScaling::setGlobalFactor(2);
|
||||
|
||||
// Verfy that QHighDpiScaling::factor() does not crash on nullptr contexts.
|
||||
QPoint fakeNativePosition = QPoint(5, 5);
|
||||
QPlatformScreen *screenContext = nullptr;
|
||||
QVERIFY(QHighDpiScaling::factor(screenContext) >= 0);
|
||||
QVERIFY(QHighDpiScaling::factor(screenContext, &fakeNativePosition) >= 0);
|
||||
QPlatformScreen *platformScreenContext = nullptr;
|
||||
QVERIFY(QHighDpiScaling::factor(platformScreenContext) >= 0);
|
||||
QVERIFY(QHighDpiScaling::factor(platformScreenContext, &fakeNativePosition) >= 0);
|
||||
QWindow *windowContext = nullptr;
|
||||
QVERIFY(QHighDpiScaling::factor(windowContext) >= 0);
|
||||
QVERIFY(QHighDpiScaling::factor(windowContext, &fakeNativePosition) >= 0);
|
||||
}
|
||||
|
||||
// QTBUG-77255: Test some scaling overloads
|
||||
void tst_QHighDpiScaling::scale()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user