From 97cf00c506889b83cfca2c2f33ad850a9f62d340 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Fri, 16 Jul 2021 20:50:27 +0200 Subject: [PATCH] Fix crashes --- submodules/Display/Source/TextNode.swift | 9 ++++++++- .../Sources/PeerInfoAvatarListNode.swift | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/submodules/Display/Source/TextNode.swift b/submodules/Display/Source/TextNode.swift index 6df461f382..3d36be6ece 100644 --- a/submodules/Display/Source/TextNode.swift +++ b/submodules/Display/Source/TextNode.swift @@ -1025,7 +1025,14 @@ public class TextNode: ASDisplayNode { layoutSize.height += fontLineSpacing } - let lineRange = CFRangeMake(lastLineCharacterIndex, lineCharacterCount) + var lineRange = CFRangeMake(lastLineCharacterIndex, lineCharacterCount) + if lineRange.location + lineRange.length > attributedString.length { + lineRange.length = attributedString.length - lineRange.location + } + if lineRange.length < 0 { + break + } + let coreTextLine = CTTypesetterCreateLineWithOffset(typesetter, lineRange, 100.0) lastLineCharacterIndex += lineCharacterCount diff --git a/submodules/PeerInfoAvatarListNode/Sources/PeerInfoAvatarListNode.swift b/submodules/PeerInfoAvatarListNode/Sources/PeerInfoAvatarListNode.swift index bfd6117b7d..3321f1a84a 100644 --- a/submodules/PeerInfoAvatarListNode/Sources/PeerInfoAvatarListNode.swift +++ b/submodules/PeerInfoAvatarListNode/Sources/PeerInfoAvatarListNode.swift @@ -125,11 +125,14 @@ public enum PeerInfoAvatarListItem: Equatable { } } - public init(entry: AvatarGalleryEntry) { + public init?(entry: AvatarGalleryEntry) { switch entry { case let .topImage(representations, videoRepresentations, _, _, immediateThumbnailData, _): self = .topImage(representations, videoRepresentations, immediateThumbnailData) case let .image(_, reference, representations, videoRepresentations, _, _, _, _, immediateThumbnailData, _): + if representations.isEmpty { + return nil + } self = .image(reference, representations, videoRepresentations, immediateThumbnailData) } } @@ -876,6 +879,9 @@ public final class PeerInfoAvatarListContainerNode: ASDisplayNode { entries.append(entry) items.append(.topImage(representations, videoRepresentations, immediateThumbnailData)) case let .image(_, reference, representations, videoRepresentations, _, _, _, _, immediateThumbnailData, _): + if representations.isEmpty { + continue + } if image.0 == reference { entries.insert(entry, at: 0) items.insert(.image(reference, representations, videoRepresentations, immediateThumbnailData), at: 0) @@ -916,6 +922,9 @@ public final class PeerInfoAvatarListContainerNode: ASDisplayNode { entries.append(entry) items.append(.topImage(representations, videoRepresentations, immediateThumbnailData)) case let .image(_, reference, representations, videoRepresentations, _, _, _, _, immediateThumbnailData, _): + if representations.isEmpty { + continue + } if image.0 != reference { entries.append(entry) items.append(.image(reference, representations, videoRepresentations, immediateThumbnailData)) @@ -1014,7 +1023,9 @@ public final class PeerInfoAvatarListContainerNode: ASDisplayNode { items.append(.custom(customNode)) } for entry in entries { - items.append(PeerInfoAvatarListItem(entry: entry)) + if let item = PeerInfoAvatarListItem(entry: entry) { + items.append(item) + } } strongSelf.galleryEntries = entries strongSelf.items = items