diff --git a/Sources/Gtk3/Widgets/Image+ManualAdditions.swift b/Sources/Gtk3/Widgets/Image+ManualAdditions.swift index e7bbf049256..593e7cb6f69 100644 --- a/Sources/Gtk3/Widgets/Image+ManualAdditions.swift +++ b/Sources/Gtk3/Widgets/Image+ManualAdditions.swift @@ -1,6 +1,10 @@ import CGtk3 extension Image { + public func clear() { + gtk_image_clear(castedPointer()) + } + public func setPath(_ path: String) { gtk_image_set_from_file(castedPointer(), path) } diff --git a/Sources/Gtk3Backend/Gtk3Backend.swift b/Sources/Gtk3Backend/Gtk3Backend.swift index ede50cbc91c..1563d046f91 100644 --- a/Sources/Gtk3Backend/Gtk3Backend.swift +++ b/Sources/Gtk3Backend/Gtk3Backend.swift @@ -677,6 +677,12 @@ public final class Gtk3Backend: AppBackend { ) { let imageView = imageView as! Gtk3.Image + // Check if the resulting image would be empty + guard targetWidth > 0, targetHeight > 0 else { + imageView.clear() + return + } + let pixbuf = Pixbuf( rgbaData: rgbaData, width: width,