MixedRealityToolkit-Unity
MixedRealityToolkit-Unity copied to clipboard
The dependency on the "CanvasProxyInteractor" is not made clear at all
Describe the issue
We ran in to some very odd issues with the MRTK UX, to the point where null reference exceptions where appearing sporadically as the UI was being hovered over or interacted with.
On investigation, ALL of the errors were due to the absence of the "CanvasProxyInteractor" being active in the scene.
Feature area
If a component, such as the "CanvasProxyInteractor" interactor is required for features to work within a MRTK scene, then it both needs to:
- Be identified by components that rely on it (e.g. a UX component on a Canvas using a "UGUI input adapter") should highlight that a dependency is missing from the scene, be it a "CanvasProxyInteractor" or another "IProxyInteractor" style class
- Documentation needs to be clearer to STATE that such a component needs to be in a scene if it is a depdendency.
Can you please provide a callstack from any of the null reference exceptions?
LMGTFY
Two exception stacks I can offer after breaking the solution again (disabling the "CanvasProxyInteractor")
NullReferenceException: Object reference not set to an instance of an object
Microsoft.MixedReality.Toolkit.UX.UGUIInputAdapter.OnPointerEnter (UnityEngine.EventSystems.PointerEventData pointerEventData) (at Library/PackageCache/com.microsoft.mrtk.uxcore@421d14e45036/Interop/UGUIInputAdapter.cs:195)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerEnterHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at Library/PackageCache/[email protected]/Runtime/EventSystem/ExecuteEvents.cs:22)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at Library/PackageCache/[email protected]/Runtime/EventSystem/ExecuteEvents.cs:262)
UnityEngine.XR.Interaction.Toolkit.UI.UIInputModule:Update() (at Library/PackageCache/[email protected]/Runtime/UI/UIInputModule.cs:111)
NullReferenceException: Object reference not set to an instance of an object
Microsoft.MixedReality.Toolkit.UX.UGUIInputAdapter.OnDeselect (UnityEngine.EventSystems.BaseEventData eventData) (at Library/PackageCache/com.microsoft.mrtk.uxcore@421d14e45036/Interop/UGUIInputAdapter.cs:270)
Microsoft.MixedReality.Toolkit.UX.UGUIInputAdapter.OnPointerExit (UnityEngine.EventSystems.PointerEventData pointerEventData) (at Library/PackageCache/com.microsoft.mrtk.uxcore@421d14e45036/Interop/UGUIInputAdapter.cs:211)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerExitHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at Library/PackageCache/[email protected]/Runtime/EventSystem/ExecuteEvents.cs:29)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at Library/PackageCache/[email protected]/Runtime/EventSystem/ExecuteEvents.cs:262)
UnityEngine.XR.Interaction.Toolkit.UI.UIInputModule:Update() (at Library/PackageCache/[email protected]/Runtime/UI/UIInputModule.cs:111)
Both are caused by the same effect, as the "protected IProxyInteractor ProxyInteractor" lookup fails to find any registered "IProxyInteractors" active in the scene and just returns NULL, causing ANY events requesting it to cause a NullReference check. This would in theory affect any of the events in the "UGUIInputAdapter".
What I do not understand is what the failure is sporadic, does not always occur and will raise an exception on one "StatefulInteractable" object and not another.
But handling the null reference failure is also wise @keveleigh :D
Thanks for the call stacks! CC @Zee2
@SimonDarksideJ, well aware of this; will be fixed in an upcoming update. UGUIInputAdapter will gracefully fallback if no proxy interactor is available.
In addition, we're going to be baking the proxy interactor into the default rig prefab to help avoid these points of confusion in the future!
Fixed in #10711.
Fixed in #10711.
@Zee2 just to clarify, I'm not sure I see the two potential null refs mentioned above changed in that PR.
It seems like the following two sections would still null ref if ProxyInteractor
is null (along with some others as I was looking through), unless your change in that PR prevents these methods from being called?
https://github.com/microsoft/MixedRealityToolkit-Unity/blob/45ea6a3b2a6bd5fef1ff3e1f7b5b8c25416850c9/com.microsoft.mrtk.uxcore/Interop/UGUIInputAdapter.cs#L206-L209
https://github.com/microsoft/MixedRealityToolkit-Unity/blob/45ea6a3b2a6bd5fef1ff3e1f7b5b8c25416850c9/com.microsoft.mrtk.uxcore/Interop/UGUIInputAdapter.cs#L285-L288
You're right that it doesn't technically guard against those nullrefs; but, then again, they'd have very little reason to occur if the proxy interactor was baked into the rig.
I'll open this again for a future PR that'll do more safeguarding/explanation.
NREs resolved here!