Fix ActivityItemContent QML paintedWidth errors
authorClaudio Cambra <claudio.cambra@gmail.com>
Fri, 15 Jul 2022 10:47:48 +0000 (12:47 +0200)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Mon, 18 Jul 2022 14:06:28 +0000 (14:06 +0000)
Signed-off-by: Claudio Cambra <claudio.cambra@gmail.com>
src/gui/tray/ActivityItemContent.qml

index 785dccbdba31856f407ee3bcec7e479d43af63bc..90134f73268490abf06cdf3a91a5e1a9a4d74806 100644 (file)
@@ -81,16 +81,21 @@ RowLayout {
             width: model.thumbnail !== undefined ? parent.width * 0.4 : thumbnailItem.imageWidth
             height: model.thumbnail !== undefined ? width : width * 0.9
 
+            // Prevent bad access into unloaded item properties
+            readonly property int thumbnailPaintedWidth: thumbnailImageLoader.item ? thumbnailImageLoader.item.paintedWidth : 0
+            readonly property int thumbnailPaintedHeight: thumbnailImageLoader.item ? thumbnailImageLoader.item.paintedHeight : 0
+
             readonly property int negativeLeftMargin: -((width / 2) +
                                                         ((width - paintedWidth) / 2) +
                                                         ((thumbnailImageLoader.width - thumbnailItem.imageWidth) / 2) +
-                                                        ((thumbnailImageLoader.width - thumbnailImageLoader.item.paintedWidth) / 2) +
+                                                        ((thumbnailImageLoader.width - thumbnailPaintedWidth) / 2) +
                                                         (thumbnailItem.thumbnailRadius / 4))
             readonly property int negativeTopMargin: -((height / 2) +
                                                        ((height - paintedHeight) / 2) +
                                                        ((thumbnailImageLoader.height - thumbnailItem.imageHeight) / 4) +
-                                                       ((thumbnailImageLoader.height - thumbnailImageLoader.item.paintedHeight) / 4) +
+                                                       ((thumbnailImageLoader.height - thumbnailPaintedHeight) / 4) +
                                                        (thumbnailItem.thumbnailRadius / 4))
+
             anchors.verticalCenter: if(model.thumbnail === undefined) parent.verticalCenter
             anchors.left: model.thumbnail === undefined ? parent.left : thumbnailImageLoader.right
             anchors.leftMargin: if(model.thumbnail !== undefined) negativeLeftMargin