Skip to content

Commit d914988

Browse files
fixing issue with iOS black screen where message queue constructor would get stripped out MTT-2663 (#592)
Instead of trying to dynamically spawn message queues using reflection, we're now instantiating them manually in application controller. This way, they won't get stripped out by IL2CPP's code stripping (which can't be deactivated). Another solution could have been to use ref types for messages instead of value types, since those won't get stripped in generic types. However this creates allocations each time we're sending a message internally.
1 parent 38608eb commit d914988

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

Assets/BossRoom/Scripts/Shared/ApplicationController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ private void Awake()
4747
scope.BindAsSingle<LocalLobby>();
4848

4949
//this message channel is essential and persists for the lifetime of the lobby and relay services
50-
scope.BindMessageChannel<UnityServiceErrorMessage>();
50+
scope.BindMessageChannelInstance<UnityServiceErrorMessage>();
5151

5252
//this message channel is essential and persists for the lifetime of the lobby and relay services
53-
scope.BindMessageChannel<ConnectStatus>();
53+
scope.BindMessageChannelInstance<ConnectStatus>();
5454

5555
//buffered message channels hold the latest received message in buffer and pass to any new subscribers
56-
scope.BindBufferedMessageChannel<LobbyListFetchedMessage>();
56+
scope.BindBufferedMessageChannelInstance<LobbyListFetchedMessage>();
5757

5858
//all the lobby service stuff, bound here so that it persists through scene loads
5959
scope.BindAsSingle<AuthenticationServiceFacade>(); //a manager entity that allows us to do anonymous authentication with unity services

Assets/BossRoom/Scripts/Shared/Infrastructure/DIScope.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,18 @@ public void BindInstanceAsSingle<TImplementation, TInterface>(TImplementation in
179179
BindInstanceAsSingle(instance);
180180
}
181181

182+
public void BindInstanceAsSingle<TImplementation, TInterface, TInterface2, TInterface3>(TImplementation instance)
183+
where TImplementation : class, TInterface, TInterface2, TInterface3
184+
where TInterface : class
185+
where TInterface2 : class
186+
where TInterface3 : class
187+
{
188+
BindInstanceAsSingle<TInterface>(instance);
189+
BindInstanceAsSingle<TInterface2>(instance);
190+
BindInstanceAsSingle<TInterface3>(instance);
191+
BindInstanceAsSingle(instance);
192+
}
193+
182194
void BindInstanceToType(object instance, Type type)
183195
{
184196
m_TypesToInstances[type] = instance;

Assets/BossRoom/Scripts/Shared/Infrastructure/PubSub/MessageChannelDIExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ namespace Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure
22
{
33
public static class MessageChannelDIExtensions
44
{
5-
public static void BindMessageChannel<TMessage>(this DIScope scope)
5+
public static void BindMessageChannelInstance<TMessage>(this DIScope scope)
66
{
7-
scope.BindAsSingle< MessageChannel<TMessage>, IPublisher<TMessage>, ISubscriber<TMessage>, IMessageChannel<TMessage>>();
7+
scope.BindInstanceAsSingle<MessageChannel<TMessage>, IPublisher<TMessage>, ISubscriber<TMessage>, IMessageChannel<TMessage>>(new MessageChannel<TMessage>());
88
}
99

10-
public static void BindBufferedMessageChannel<TMessage>(this DIScope scope)
10+
public static void BindBufferedMessageChannelInstance<TMessage>(this DIScope scope)
1111
{
12-
scope.BindAsSingle< BufferedMessageChannel<TMessage>, IPublisher<TMessage>, ISubscriber<TMessage>, IBufferedMessageChannel<TMessage>>();
12+
scope.BindInstanceAsSingle<BufferedMessageChannel<TMessage>, IPublisher<TMessage>, ISubscriber<TMessage>, IBufferedMessageChannel<TMessage>>(new BufferedMessageChannel<TMessage>());
1313
}
1414
}
1515
}

0 commit comments

Comments
 (0)