From e6204b12cd560a465c6a19f30ddf06437899946d 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. Task-number: QTBUG-82434 Change-Id: Ie847865a0d868043571faf4b7f4fdf6a92fce448 Reviewed-by: Eirik Aavitsland (cherry picked from commit af0edfbc7c33261d11b559cb4842045457adc4a1) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit b63f92bb0fc75880ce0b90cce7ef9c6a092bbc2c) --- 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 77903f6b6ff..01f3aeffc2e 100644 --- a/src/plugins/platforms/windows/qwindowscursor.cpp +++ b/src/plugins/platforms/windows/qwindowscursor.cpp @@ -103,14 +103,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) @@ -121,6 +123,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());