Ejemplo n.º 1
0
            public MagicLeapProvider()
            {
                // ARFoundation often beats XRManagement to the instantiation so often times the MagicLeapPrivileges
                // class will not be available to get privileges from.  Because of this the class is acquired here.
                MagicLeapPrivileges.Initialize();

                m_PerceptionHandle = PerceptionHandle.Acquire();


                if (s_NativeProviderPtr == IntPtr.Zero)
                {
                    s_NativeProviderPtr = Native.Construct();
                }
                if (RequestPrivilegesIfNecessary())
                {
                    if (s_NativeTrackerCreationJobHandle.Equals(default(JobHandle)))
                    {
                        RcoApi.Retain(s_NativeProviderPtr);
                        s_NativeTrackerCreationJobHandle = new CreateNativeImageTrackerJob {
                            nativeProvider = s_NativeProviderPtr
                        }.Schedule();
                    }
                }
                else
                {
                    LogWarning($"Could not start the image tracking subsystem because privileges were denied.");
                }
            }
Ejemplo n.º 2
0
 public void PassingAnInvalidHandleLogsAUsefulError()
 {
     using (var handle = PerceptionHandle.Acquire())
     {
         var result = TryGetPose(CoordinateFrameId.Invalid, out var pose);
         Assert.That(() => result, Is.False);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Utility function set up instance and tracks successful _startCount
        /// </summary>
        /// <param name="requiresXRLoader">Flag to determine if this API requires the XR Loader being initialized.</param>
        /// <returns>
        /// MLResult.Result will be <c>MLResult.Code.Ok</c> if successful.
        /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to internal error (MagicLeap XR Loader not loaded, no device, DLL not found, no API symbols).
        /// MLResult.Result will otherwise be return value specific API's StartAPI function.
        /// </returns>
        protected static MLResult BaseStart(bool requiresXRLoader = false)
        {
            MLResult result;

            try
            {
                // Check to see if we have already successfully initialized a valid instance
                if (startCount > 0)
                {
                    startCount++;
                    result = MLResult.Create(MLResult.Code.Ok);
                }
                else
                {
                    if (requiresXRLoader && !MLDevice.IsReady())
                    {
                        MLPluginLog.ErrorFormat("MLAPISingleton.BaseStart failed to start {0} API. Reason: MagicLeap XR Loader is not initialized. Please wait to start API until Monobehavior.Start and if issue persists make sure ProjectSettings/XR/Initialize On Startup is enabled.", typeof(T).Name);
                        return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MagicLeap XR Loader not initialized"));
                    }

                    result = Instance.StartAPI();
                    if (result.IsOk)
                    {
                        // Everything started correctly register the update and increament _startCount
                        MLDevice.RegisterUpdate(Instance.Update);
                        MLDevice.RegisterApplicationPause(Instance.OnApplicationPause);
                        startCount++;

                        Instance.perceptionHandle     = PerceptionHandle.Acquire();
                        Instance.perceptionHasStarted = true;
                    }
                    else
                    {
                        MLPluginLog.ErrorFormat("MLAPISingleton.BaseStart failed to start {0} API. Reason: {1}", typeof(T).Name, result);
                        _instance = null;
                    }
                }

                return(result);
            }
            catch (System.DllNotFoundException)
            {
                MLPluginLog.ErrorFormat(_instance.DllNotFoundError, typeof(T).Name);
                result = MLResult.Create(MLResult.Code.UnspecifiedFailure, "Dll not found");
                MLPluginLog.ErrorFormat("MLAPISingleton.BaseStart failed to start {0} API. Reason: {1}", typeof(T).Name, result);
                _instance = null;
            }
            catch (System.EntryPointNotFoundException)
            {
                string errorMessage = string.Format("{0} API symbols not found", typeof(T).Name);
                result = MLResult.Create(MLResult.Code.UnspecifiedFailure, errorMessage);
                MLPluginLog.ErrorFormat("MLAPISingleton.BaseStart failed to start {0} API. Reason: {1}", typeof(T).Name, result);
                _instance = null;
            }

            return(result);
        }
        private void StartInternal()
        {
            MLPluginLog.Debug($"Initializing {typeof(T).Name} API...");

            if (DidNativeCallSucceed(StartAPI(), $"{typeof(T).Name} Start"))
            {
                IsStarted = true;
                MLDevice.RegisterUpdate(instance.Update);
                MLDevice.RegisterApplicationPause(instance.OnApplicationPause);
                MLDevice.RegisterDestroy(instance.StopInternal);

                instance.perceptionHandle = PerceptionHandle.Acquire();
                MLPluginLog.Debug($"{typeof(T).Name} API initialized.");
            }
        }
            public MagicLeapProvider()
            {
                m_PerceptionHandle = PerceptionHandle.Acquire();

                if (s_NativeProviderPtr == IntPtr.Zero)
                {
                    s_NativeProviderPtr = Native.Construct();
                }
                if (RequestPrivilegesIfNecessary())
                {
                    if (s_NativeTrackerCreationJobHandle.Equals(default(JobHandle)))
                    {
                        RcoApi.Retain(s_NativeProviderPtr);
                        s_NativeTrackerCreationJobHandle = new CreateNativeImageTrackerJob {
                            nativeProvider = s_NativeProviderPtr
                        }.Schedule();
                    }
                }
                else
                {
                    LogWarning($"Could not start the image tracking subsystem because privileges were denied.");
                }
            }
 public Provider()
 {
     m_PerceptionHandle = PerceptionHandle.Acquire();
 }
Ejemplo n.º 7
0
 public void CanSuccesfullyAcquirePerceptionHandle()
 {
     using (var handle = PerceptionHandle.Acquire())
         Assert.That(() => handle.active, Is.True);
 }
Ejemplo n.º 8
0
 public MagicLeapProvider()
 {
     m_PerceptionHandle = PerceptionHandle.Acquire();
 }
 public Provider()
 {
     m_PerceptionHandle = PerceptionHandle.Acquire();
     RequestPrivilegesIfNecessary();
 }