Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves issue that causes numerous exceptions of the Focus Provider has not been configured. #143

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Runtime/Input/Interactables/InteractableCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ private void AssignWorldCanvasCamera()
{
if (ServiceManager.IsActiveAndInitialized &&
ServiceManager.Instance.TryGetService<IInputService>(out var inputService) &&
canvas.isRootCanvas && canvas.renderMode == RenderMode.WorldSpace)
canvas.isRootCanvas && canvas.renderMode == RenderMode.WorldSpace &&
inputService.FocusProvider != null)
{
canvas.worldCamera = inputService.FocusProvider.UIRaycastCamera;
}
Expand Down
5 changes: 5 additions & 0 deletions Runtime/Input/Interactors/GenericPointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public GenericPointer(string pointerName, IInputSource inputSourceParent)
{
if (ServiceManager.Instance.TryGetService<IInputService>(out var inputService))
{
if(inputService.FocusProvider == null)
{
throw new InvalidOperationException(IFocusProvider.MissingFocusProviderMessage);
}

PointerId = inputService.FocusProvider.GenerateNewPointerId();
PointerName = pointerName;
this.inputSourceParent = inputSourceParent;
Expand Down
2 changes: 2 additions & 0 deletions Runtime/Input/Interfaces/IFocusProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace RealityToolkit.Input.Interfaces
/// </summary>
public interface IFocusProvider : ISourceStateHandler, IInputServiceModule
{
public static string MissingFocusProviderMessage = $"Couldn't find a valid {nameof(IFocusProvider)} configured for the {nameof(IInputService)}!\nPlease ensure that at least a Focus Provider has been registered with the {nameof(IInputService)}";
FejZa marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// The Physics Layers, in prioritized order, that are used to determine the <see cref="IInteractorResult.CurrentTarget"/> when raycasting.
/// </summary>
Expand Down
9 changes: 7 additions & 2 deletions Runtime/Input/Modules/GazeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ protected virtual async void Start()
// We've been destroyed during the await.
if (this == null) { return; }

if (GazePointer == null && inputService.FocusProvider == null)
{
throw new InvalidOperationException(IFocusProvider.MissingFocusProviderMessage);
}

lateInitialize = false;
InputService.Register(gameObject);

Expand Down Expand Up @@ -376,7 +381,7 @@ protected virtual void OnDisable()
{
InputService?.Unregister(gameObject);

if (GazePointer.BaseCursor != null)
if (GazePointer != null && GazePointer.BaseCursor != null)
{
GazePointer.BaseCursor.IsVisible = false;
}
Expand Down Expand Up @@ -434,7 +439,7 @@ void IInputHandler.OnInputDown(InputEventData eventData)

private IInteractor InitializeGazePointer()
{
if (InputService == null) { return null; }
if (InputService == null || InputService.FocusProvider == null) { return null; }

if (gazeTransform == null)
{
Expand Down