MixedRealityToolkit-Unity: InputSystemDisable() followed by InputSystem.Enable causes NullPointerExceptions
Overview
Disabling and then re-enabling the input system causes the following exception to be thrown every frame:
NullReferenceException: Object reference not set to an instance of an object
Microsoft.MixedReality.Toolkit.Input.FocusProvider.RegisterPointers (Microsoft.MixedReality.Toolkit.Input.IMixedRealityInputSource inputSource) (at Assets/MixedRealityToolkit.Services/InputSystem/FocusProvider.cs:689)
Steps to reproduce
Use the following script to enable and disable the input system. Notice that after enabling the input system console spits out continuous null pointers:
using Microsoft.MixedReality.Toolkit;
using Microsoft.MixedReality.Toolkit.Input;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DisableInputSystemTest : MonoBehaviour
{
private IMixedRealityInputSystem inputSystem = null;
private IMixedRealityInputSystem InputSystem
{
get
{
if (inputSystem == null)
{
MixedRealityServiceRegistry.TryGetService<IMixedRealityInputSystem>(out inputSystem);
}
return inputSystem;
}
}
public void DisableInputSystem()
{
InputSystem.Disable();
}
public void EnableInputSystem()
{
InputSystem.Enable();
}
public void Update()
{
if (Input.GetKeyDown(KeyCode.Alpha1))
{
EnableInputSystem();
}
if (Input.GetKeyDown(KeyCode.Alpha2))
{
DisableInputSystem();
}
}
}
Unity Editor Version
2018.4.1f1
Mixed Reality Toolkit Release Version
mrtk_development latest
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (15 by maintainers)
on a longer term :
if you want users to avoid accessing some functions, you may go with internal interfaces.
http://www.csharp411.com/c-internal-interface/
together with InternalsVisibleToAttribute to be able to have internal calls cross-mrtk-assemblies
the only tricky thing is you have to cast (or store) the MyService to IMixedRealityServiceInternal to be able to call the internal function or use some extensions tricks
this may be a lot of refactor but will clearly show what can be called from the public interface to users 😃