Fix crash in rounding of shared images.

Regression was introduced in 721d143c89.
This commit is contained in:
John Preston 2020-02-25 13:17:00 +04:00
parent be5ed0053a
commit ccc12ce3da

View file

@ -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<uint32*>(image.bits());
constexpr auto imageIntsPerPixel = 1;
auto imageIntsPerLine = (image.bytesPerLine() >> 2);
Assert(image.depth() == static_cast<int>((imageIntsPerPixel * sizeof(uint32)) << 3));
Assert(image.bytesPerLine() == (imageIntsPerLine << 2));
auto ints = reinterpret_cast<uint32*>(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;