From ccc12ce3da8f9ac30f30228c225585f732f74d5f Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 25 Feb 2020 13:17:00 +0400 Subject: [PATCH] Fix crash in rounding of shared images. Regression was introduced in 721d143c89. --- ui/image/image_prepare.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ui/image/image_prepare.cpp b/ui/image/image_prepare.cpp index 176e307..c774456 100644 --- a/ui/image/image_prepare.cpp +++ b/ui/image/image_prepare.cpp @@ -463,12 +463,17 @@ void prepareRound( if (imageWidth < 2 * cornerWidth || imageHeight < 2 * cornerHeight) { return; } + + // We need to detach image first (if it is shared), before we + // count some offsets using QImage::bytesPerLine etc, because + // bytesPerLine may change on detach, this leads to crashes: + // Real image bytesPerLine is smaller than the one we use for offsets. + auto ints = reinterpret_cast(image.bits()); + constexpr auto imageIntsPerPixel = 1; auto imageIntsPerLine = (image.bytesPerLine() >> 2); Assert(image.depth() == static_cast((imageIntsPerPixel * sizeof(uint32)) << 3)); Assert(image.bytesPerLine() == (imageIntsPerLine << 2)); - - auto ints = reinterpret_cast(image.bits()); auto intsTopLeft = ints + target.x() + target.y() * imageIntsPerLine; auto intsTopRight = ints + target.x() + target.width() - cornerWidth + target.y() * imageIntsPerLine; auto intsBottomLeft = ints + target.x() + (target.y() + target.height() - cornerHeight) * imageIntsPerLine;