Jump to content

PavelP

Verified Members
  • Posts

    1
  • Joined

  • Last visited

Posts posted by PavelP

  1. On 6/23/2020 at 5:15 PM, Corvus said:

    @wdrake @fayre If anyone is experiencing crashes with Unity and threads feel free to use the callback method in the SDK. The thread crashes may be due to aborting a thread during an eye data update. The callback method has been reliable in my testing.

     

    
    using UnityEngine;
    using ViveSR.anipal.Eye;
    using System.Runtime.InteropServices;
    
    public class CallbackExample : MonoBehaviour
    {
    
        private EyeData eyeData = new EyeData();
        private bool eye_callback_registered = false;
    
        private void Update()
        {
            if (SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.WORKING) return;
    
            if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == true && eye_callback_registered == false)
            {
                SRanipal_Eye.WrapperRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye.CallbackBasic)EyeCallback));
                eye_callback_registered = true;
            }
            else if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == false && eye_callback_registered == true)
            {
                SRanipal_Eye.WrapperUnRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye.CallbackBasic)EyeCallback));
                eye_callback_registered = false;
            }
        }
    
        private void OnDisable()
        {
            Release();
        }
    
        void OnApplicationQuit()
        {
            Release();
        }
    
        private void Release()
        {
            if (eye_callback_registered == true)
            {
                SRanipal_Eye.WrapperUnRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye.CallbackBasic)EyeCallback));
                eye_callback_registered = false;
            }
        }
    
        private void EyeCallback(ref EyeData eye_data)
        {
            eyeData = eye_data;
            
            // do stuff with eyeData..
        }
    }

     

     

    Hi @Corvus,

    I've tried your callback method solution, unfortunately it is still crashing the Unity when I stop the game. Moreover it pretty soon throws a NullReferenceException, usually after a second or so. I attached the image with the exception.

    Výstřižek.PNG

×
×
  • Create New...