Skip to content

Conversation

@laevandus
Copy link
Contributor

@laevandus laevandus commented Nov 25, 2024

🔗 Issue Link

Resolves IOS-22

🎯 Goal

Fix a rare crash when accessing messages in the ChatChannelViewModel

🛠 Implementation

Not fully sure exact steps, but the crash was triggered when the list changes array contains .update with index pointing at invalid index. This shouldAnimate checks currently displayed messages through the self.messages, not the incoming messages array, then the index is not guaranteed to be safe. One theory is that new message was inserted and at the same time .update was also reported with the list change (e.g. [.insert, .update]).

Thread 0 name:
Thread 0 Crashed:
0   MyApp                       	0x0000000101682ca8 Swift runtime failure: Index out of range + 0 (<compiler-generated>:0)
1   MyApp                       	0x0000000101682ca8 specialized Array._checkSubscript(_:wasNativeTypeChecked:) + 4 (<compiler-generated>:0)
2   MyApp                       	0x0000000101682ca8 specialized Array.subscript.getter + 4 (<compiler-generated>:0)
3   MyApp                       	0x0000000101682ca8 specialized LazyCachedMapCollection.subscript.getter + 4 (ChatChannelViewModel.swift:0)
4   MyApp                       	0x0000000101682ca8 ChatChannelViewModel.shouldAnimate(changes:) + 3060
5   MyApp                       	0x000000010167e38c ChatChannelViewModel.dataSource(channelDataSource:didUpdateMessages:changes:) + 376 (ChatChannelViewModel.swift:422)

🧪 Testing

N/A

☑️ Checklist

  • I have signed the Stream CLA (required)
  • Changelog is updated with client-facing changes
  • New code is covered by unit tests
  • Affected documentation updated (docusaurus, tutorial, CMS (task created)

@Stream-SDK-Bot
Copy link
Collaborator

Stream-SDK-Bot commented Nov 25, 2024

SDK Size

title develop branch diff status
StreamChatSwiftUI 8.01 MB 8.01 MB 0 KB 🟢

@sonarqubecloud
Copy link

Copy link
Member

@nuno-vieira nuno-vieira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! ✅

@laevandus laevandus merged commit 1620457 into develop Nov 25, 2024
11 checks passed
@laevandus laevandus deleted the fix/should-animate-crash branch November 25, 2024 11:14
@Stream-SDK-Bot Stream-SDK-Bot mentioned this pull request Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants