From b63f92bb0fc75880ce0b90cce7ef9c6a092bbc2c Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Mon, 11 Dec 2023 17:54:51 +0100 Subject: [PATCH] QWindowsCursor: create correct DDB in createBitmapCursor() CreateCursor() expects a ddb and according the docs a ddb must be word-aligned but we created a byte-aligned ddb which results in a wrongly rendered cursor later on. Pick-to: 6.6 Task-number: QTBUG-82434 Change-Id: Ie847865a0d868043571faf4b7f4fdf6a92fce448 Reviewed-by: Eirik Aavitsland (cherry picked from commit af0edfbc7c33261d11b559cb4842045457adc4a1) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/windows/qwindowscursor.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowscursor.cpp b/src/plugins/platforms/windows/qwindowscursor.cpp index e1d1183cd58..b4168861206 100644 --- a/src/plugins/platforms/windows/qwindowscursor.cpp +++ b/src/plugins/platforms/windows/qwindowscursor.cpp @@ -105,14 +105,16 @@ static HCURSOR createBitmapCursor(const QImage &bbits, const QImage &mbits, hotSpot.setX(width / 2); if (hotSpot.y() < 0) hotSpot.setY(height / 2); - const int n = qMax(1, width / 8); - QScopedArrayPointer xBits(new uchar[height * n]); - QScopedArrayPointer xMask(new uchar[height * n]); + // a ddb is word aligned, QImage depends on bow it was created + const auto bplDdb = qMax(1, ((width + 15) >> 4) << 1); + const auto bplImg = int(bbits.bytesPerLine()); + QScopedArrayPointer xBits(new uchar[height * bplDdb]); + QScopedArrayPointer xMask(new uchar[height * bplDdb]); int x = 0; for (int i = 0; i < height; ++i) { const uchar *bits = bbits.constScanLine(i); const uchar *mask = mbits.constScanLine(i); - for (int j = 0; j < n; ++j) { + for (int j = 0; j < bplImg && j < bplDdb; ++j) { uchar b = bits[j]; uchar m = mask[j]; if (invb) @@ -123,6 +125,11 @@ static HCURSOR createBitmapCursor(const QImage &bbits, const QImage &mbits, xMask[x] = b ^ m; ++x; } + for (int i = bplImg; i < bplDdb; ++i) { + xBits[x] = 0; + xMask[x] = 0; + ++x; + } } return CreateCursor(GetModuleHandle(nullptr), hotSpot.x(), hotSpot.y(), width, height, xBits.data(), xMask.data());