From 901e19c05219fafe0068b27de4d0771b66e6af6c Mon Sep 17 00:00:00 2001 From: david-swift Date: Wed, 21 Aug 2024 17:11:35 +0200 Subject: [PATCH] Fix picture's content being cleared automatically --- Sources/Adwaita/View/Picture+.swift | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sources/Adwaita/View/Picture+.swift b/Sources/Adwaita/View/Picture+.swift index ba23c98..ccf54d0 100644 --- a/Sources/Adwaita/View/Picture+.swift +++ b/Sources/Adwaita/View/Picture+.swift @@ -18,8 +18,14 @@ extension Picture { return inspect { storage, updateProperties in if updateProperties { let pointer = storage.opaquePointer - guard let data, data != storage.fields[oldData] as? Data else { - gtk_picture_set_paintable(pointer, gdk_paintable_new_empty(0, 0)) + guard let data else { + if storage.fields[oldData] != nil { + gtk_picture_set_paintable(pointer, gdk_paintable_new_empty(0, 0)) + storage.fields[oldData] = nil + } + return + } + guard data != storage.fields[oldData] as? Data else { return } let bytes = data.withUnsafeBytes { ptr in