Azure / azure-remote-rendering

SDK and samples for Azure Remote Rendering
MIT License
107 stars 39 forks source link

[Remote rendering problem] ARRSessionService not initializing properly #108

Closed whatthemehek closed 1 year ago

whatthemehek commented 1 year ago

I am trying to create a custom ARR instance, based on the example code in this page:

https://learn.microsoft.com/en-us/azure/remote-rendering/concepts/sessions#session-phases

as well as the default RemoteRenderingCoordinator script.

When I run this code, calling InitRenderingSession() upon start:

private ARRServiceUnity arrSessionService;

private ARRServiceUnity ARRSessionService
{
    get
    {
        if (arrSessionService == null)
            arrSessionService = GetComponent<ARRServiceUnity>();
        return arrSessionService;
    }
}

async Task<RenderingSession> InitRenderingSession()
{
      RemoteManagerUnity.InitializeManager(new RemoteUnityClientInit(Camera.main));
      SessionConfiguration sessionConfig = new SessionConfiguration(AccountDomain, RemoteRenderingDomain, AccountId, AccountKey);
      RemoteRenderingClient client = new RemoteRenderingClient(sessionConfig);
      try
      {
          ARRSessionService.Initialize(sessionConfig);
      }
      catch (ArgumentException argumentException)
      {
          Debug.LogError("hello + " + argumentException.Message);
      }
      (...)
}

I get the following error on the line where I call ARRSessionService.Initialize(sessionConfig);

NullReferenceException: Object reference not set to an instance of an object
CustomScript+<InitRenderingSession>d__11.MoveNext () (at Assets/RemoteRenderingCore/Scripts/CustomScript.cs:68)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () (at <695d1cc93cca45069c528c15c9fdd749>:0)
CustomScript+<Start>d__10.MoveNext () (at Assets/RemoteRenderingCore/Scripts/CustomScript.cs:40)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) (at <695d1cc93cca45069c528c15c9fdd749>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <913bb12059fd4cef8da5cc94ad2f0933>:0)
UnityEngine.UnitySynchronizationContext:ExecuteTasks()

Why is this error occurring?

ChristopherManthei commented 1 year ago

Hi @whatthemehek ,

First, the exception is probably because you don't have a ARRServiceUnity component on your GameObject. Either make sure in the editor that you add the component to the same GameObject as your CustomScript, or add the following attribute to your component, which will ensure that the dependency is always fulfilled:

[RequireComponent(typeof(ARRServiceUnity))]
public class CustomScript : MonoBehaviour
{

Second, ARRServiceUnity is a convenience class that already takes care of creating a RemoteRenderingClient. You should either use one or the other. If you use ARRServiceUnity, you can follow either the Unity tutorial or just take the Quickstart sample code to get you started.\ If you don't want to use ARRServiceUnity and do everything by hand, you can follow the example code you linked, but for most users ARRServiceUnity should be more convenient to use.

Cheers, Christopher