Skip to content

Commit b26d09e

Browse files
authored
Feature/potential fix for android il2cpp crash (#135)
* Skip null items when converting collections to dtos * Experimental fix for Ticket(38178) - TrySaveToDtoDictionary crash on Android(7, 10, 11, 12) & IL2CPP * use TrySaveToDto + improve comment
1 parent a49696b commit b26d09e

1 file changed

Lines changed: 33 additions & 4 deletions

File tree

Assets/Plugins/StreamChat/Core/LowLevelClient/Requests/UpdateUsersRequest.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using StreamChat.Core.Helpers;
1+
using System.Collections.Generic;
2+
using StreamChat.Core.Helpers;
23
using StreamChat.Core.InternalDTO.Requests;
34

45
namespace StreamChat.Core.LowLevelClient.Requests
@@ -11,11 +12,39 @@ public partial class UpdateUsersRequest : RequestObjectBase, ISavableTo<UpdateUs
1112
/// StreamTodo: Check if this could be list
1213
public System.Collections.Generic.Dictionary<string, UserObjectRequest> Users { get; set; }
1314

14-
UpdateUsersRequestInternalDTO ISavableTo<UpdateUsersRequestInternalDTO>.SaveToDto() =>
15-
new UpdateUsersRequestInternalDTO
15+
UpdateUsersRequestInternalDTO ISavableTo<UpdateUsersRequestInternalDTO>.SaveToDto()
16+
{
17+
var dto = new UpdateUsersRequestInternalDTO
1618
{
17-
Users = Users.TrySaveToDtoDictionary<UserObjectRequestInternalDTO, UserObjectRequest, string>(),
19+
// Users = Users.TrySaveToDtoDictionary<UserObjectRequestInternalDTO, UserObjectRequest, string>(),
1820
AdditionalProperties = AdditionalProperties,
1921
};
22+
23+
// Ticket#38178 TrySaveToDtoDictionary caused crashes on old Android versions with IL2CPP
24+
// Perhaps this due to IL2CPP not handling well complex generic signatures
25+
if (Users != null)
26+
{
27+
var dict = new Dictionary<string, UserObjectRequestInternalDTO>();
28+
29+
foreach (var sourceKeyValue in Users)
30+
{
31+
if (sourceKeyValue.Value == null)
32+
{
33+
continue;
34+
}
35+
36+
var serialized = sourceKeyValue.Value.TrySaveToDto();
37+
38+
if (serialized != null)
39+
{
40+
dict.Add(sourceKeyValue.Key,serialized);
41+
}
42+
}
43+
44+
dto.Users = dict;
45+
}
46+
47+
return dto;
48+
}
2049
}
2150
}

0 commit comments

Comments
 (0)