void OnDestroy() { if (instance == null || instance != this) { return; } //Debug.Log("KM was destroyed"); // shut down the polling threads and stop the sensors if (kinectInitialized) { // close the opened sensors and release respective data for (int i = sensorDatas.Count - 1; i >= 0; i--) { KinectInterop.SensorData sensorData = sensorDatas[i]; DepthSensorInterface sensorInt = sensorData.sensorInterface; Debug.Log(string.Format("Closing S{0}: {1}", i, sensorInt.GetType().Name)); if (sensorData.pollFramesThread != null) { // stop the frame-polling thread sensorData.threadStopEvent.Set(); sensorData.pollFramesThread.Join(); sensorData.pollFramesThread = null; sensorData.threadStopEvent.Dispose(); sensorData.threadStopEvent = null; } // close the sensor KinectInterop.CloseSensor(sensorData); sensorDatas.RemoveAt(i); sensorInterfaces.RemoveAt(i); } kinectInitialized = false; } instance = null; }
// opens the default sensor and needed readers public static SensorData OpenDefaultSensor(DepthSensorInterface sensorInt, FrameSource dwFlags, float sensorAngle, bool bUseMultiSource) { SensorData sensorData = null; if (sensorInt == null) { return(sensorData); } try { if (sensorData == null) { sensorData = sensorInt.OpenDefaultSensor(dwFlags, sensorAngle, bUseMultiSource); if (sensorData != null) { sensorData.sensorInterface = sensorInt; sensorData.sensorIntPlatform = sensorInt.GetSensorPlatform(); Debug.Log("Interface used: " + sensorInt.GetType().Name); Debug.Log("Shader level: " + SystemInfo.graphicsShaderLevel); } } else { sensorInt.FreeSensorInterface(false); } } catch (Exception ex) { Debug.LogError("Initialization of the sensor failed."); Debug.LogError(ex.ToString()); try { sensorInt.FreeSensorInterface(false); } catch (Exception) { // do nothing } } return(sensorData); }