Azure / azure-remote-rendering

SDK and samples for Azure Remote Rendering
MIT License
106 stars 38 forks source link

RemoteManagerUnity.IsConnected returns True for a frame after calling CurrentActiveSession.ConnectAsync before actually connecting in certain circumstances #32

Closed WikkidEdd closed 3 years ago

WikkidEdd commented 3 years ago

Describe the problem

We've been tracking down a problem where we're getting "[RRClient] Object accessed with incorrect generation" warning spew and "RRException: An error occurred: InvalidId (107)" exception after reconnection.

The cause of those warnings and exceptions was to do with the way RemoteClipBox works. In its update loop, it checked to see whether RemoteManagerUnity.IsConnected is true and if so creates the remote ARRCutPlaneComponents. After a lot of investigation, we found that RemoteManagerUnity.IsConnected was returning true momentarily before the connection was actually established. This caused the remote ARRCutPlaneComponents to be created too early and presumably creating invalid ARRCutPlaneComponents.

Digging further we found that immediately after calling CurrentActiveSession.ConnectAsync(), RemoteManagerUnity.IsConnected was returning true until CurrentActiveSession.Connection.Update() is called.

This only occurs after CurrentActiveSession.Disconnect() and ARRServiceUnity.ForgetSession() and then ARRServiceUnity.OpenSession() and CurrentActiveSession.ConnectAsync().

We can easily work around the specific issue with RemoteClipBox, but it seems like this could lead to other issues, so it should probably be fixed.

Provide additional information

You can observe the issue in the Quickstart sample if you add the following to the RemoteRendering.cs

private void OnGUI()
    {
        if(GUILayout.Button("Connect"))
        {
            AutoStartSessionAsync();
        }
        if(GUILayout.Button("Disconnect"))
        {
            DisconnectSession();
            arrService.ForgetSession();
        }
    }

and then this debug line after ConnectAndLoadModel() at the bottom of AutoStartSessionAsync() Debug.Log($"RemoteManagerUnity.IsConnected {RemoteManagerUnity.IsConnected}");

Now if you press play. Let the ARR instance start and connect, then click "Disconnect" in the on-screen UI followed by "Connect" shortly after. On the first connection attempt, the debug log will show "RemoteManagerUnity.IsConnected False" and on the second attempt, it will show "RemoteManagerUnity.IsConnected True"

jumeder commented 3 years ago

Hi @WikkidEdd, thank you for your bug report and thanks a ton for your preliminary work! I've logged this issue internally with the team and we'll investigate it.

jumeder commented 3 years ago

Hi again @WikkidEdd! We changed the API behavior you describe in the new 1.0.7 release. The connection state change will now be immediate on calling RenderingSession.Disconnect and on calling RenderingSession.ConnectAsync. As this change is client side, it requires an update to the 1.0.7 sdk.

I'm closing this ticket for now. Feel free to reopen as necessary.