From b7f6652e97bb7ea3c82049e610d8dba8f542848a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Thu, 27 Aug 2026 22:10:35 +0200 Subject: [PATCH] fix: Crash on avatar size <= 0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Assisted-by: ClaudeCode:claude-opus-5 Signed-off-by: Marcel Müller --- NextcloudTalk/Settings/NCUtils.swift | 3 +++ NextcloudTalk/User Interface/AvatarView.swift | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/NextcloudTalk/Settings/NCUtils.swift b/NextcloudTalk/Settings/NCUtils.swift index f0d9807c9..00a0c76b7 100644 --- a/NextcloudTalk/Settings/NCUtils.swift +++ b/NextcloudTalk/Settings/NCUtils.swift @@ -371,6 +371,9 @@ import AVFoundation public static func renderAspectImage(image: UIImage?, ofSize size: CGSize, scale: CGFloat, centerImage center: Bool) -> UIImage? { guard let image else { return nil } + // UIGraphicsBeginImageContextWithOptions raises an exception for empty or non finite sizes + guard size.width > 0, size.height > 0, size.width.isFinite, size.height.isFinite else { return nil } + let newRect = CGRect(x: 0, y: 0, width: size.width, height: size.height) UIGraphicsBeginImageContextWithOptions(newRect.size, false, scale) diff --git a/NextcloudTalk/User Interface/AvatarView.swift b/NextcloudTalk/User Interface/AvatarView.swift index 5b652b793..bf992b949 100644 --- a/NextcloudTalk/User Interface/AvatarView.swift +++ b/NextcloudTalk/User Interface/AvatarView.swift @@ -140,6 +140,12 @@ import SDWebImage // MARK: - User status public func setStatus(for room: NCRoom, allowCustomStatusIcon statusIconAllowed: Bool) { + self.room = room + self.allowCustomStatusIcon = statusIconAllowed + + // layoutSubviews can run while the view is collapsed, rendering a status image of that size would raise an exception + guard statusImageSize(padding: 2) > 0 else { return } + if room.type == .oneToOne, let roomStatus = room.status { if roomStatus != "dnd", statusIconAllowed, let roomStatusIcon = room.statusIcon { setUserStatusIcon(roomStatusIcon) @@ -164,9 +170,6 @@ import SDWebImage } } - self.room = room - self.allowCustomStatusIcon = statusIconAllowed - setUserStatusImageViewCutoutLayer() }