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() }