Exception sending a Command just as network object is destroyed

In a high frequency Command (part of our combat system) we are sending an attack Command to the simulator just as the target object has been destroyed over the network. The internal of the Sync.SendCommand is throwing an exception because the sync.CoherenceBridge is already null. This is a problem because to our application the Sync object is still active an enabled.

It looks like network destroys spawn “destroyRoutine” task that waits a frame before truly cleaning up (line 1189 of CoherenceSync). If we happen to send a command during this one frame delay the internals of the Sync are half destroyed and throws the exception below.

System.NullReferenceException: Object reference not set to an instance of an object
  at Coherence.Toolkit.CommandsHandler.GetCommandNameAndValidateEntityId (System.Type targetType, System.String methodName, System.String& commandName) [0x000b0] in ./Library/PackageCache/io.coherence.sdk@1.1.5/Coherence.Toolkit/CommandHandler.cs:320 
  at Coherence.Toolkit.CommandsHandler.SendCommand (System.Type targetType, System.String methodName, Coherence.MessageTarget target, System.Boolean sendToAllBindings, System.Object[] args) [0x00001] in ./Library/PackageCache/io.coherence.sdk@1.1.5/Coherence.Toolkit/CommandHandler.cs:152 
  at Coherence.Toolkit.CoherenceSync.SendCommand (System.Type targetType, System.String methodName, Coherence.MessageTarget target, System.Object[] args) [0x00001] in ./Library/PackageCache/io.coherence.sdk@1.1.5/Coherence.Toolkit/CoherenceSync.cs:1476 
  at Coherence.Toolkit.CoherenceSync.SendCommand[TTarget] (System.String methodName, Coherence.MessageTarget target, System.Object[] args) [0x00001] in ./Library/PackageCache/io.coherence.sdk@1.1.5/Coherence.Toolkit/CoherenceSync.cs:1463

Expected behaviour

Either the sync should be null right when the network destroy comes in, or the Command should gracefully fail by checking if the Sync.CoherenceBridge is null before checking if connected.

Screenshots


How to reproduce

You need to be in a situation where you send a command during the 1 frame delay during network destroys.

As a workaround I can probably manually check the sync.CoherenceBridge for null before trying the SendCommand.

Environment

SDK: 1.1.5
Unity: 2022.3.19f1
OS/Platform: OSX

Thanks!

Hey, excellent info here. We think you’re absolutely right and will address this in an update sooner rather than later.

1 Like

Hey, we’re shipping a fix for this on 1.2.2, which will be out no later than tomorrow early next week (we’ve decided to postpone the release so that the team can be around, so in case something comes up we can be around).

1 Like

Fix made it into 1.2.2 earlier this month - was it addressing the issue you were facing?