File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -111,16 +111,7 @@ public void Initialize()
111111
112112 public void Shutdown ( )
113113 {
114- // BodyFrameReader is IDisposable
115- BodyFrameReader ? . Dispose ( ) ;
116- BodyFrameReader = null ;
117-
118- // Close the kinect sensor
119- KinectSensor ? . Close ( ) ;
120- KinectSensor = null ;
121-
122- // Mark as not initialized
123- IsInitialized = false ;
114+ ShutdownInternal ( ) ;
124115 }
125116
126117 public void Update ( )
@@ -133,12 +124,42 @@ public void SignalJoint(int jointId)
133124 // ignored
134125 }
135126
127+ private void ShutdownInternal ( bool unInitialize = true )
128+ {
129+ // BodyFrameReader is IDisposable
130+ BodyFrameReader ? . Dispose ( ) ;
131+ BodyFrameReader = null ;
132+
133+ // Close the kinect sensor
134+ KinectSensor ? . Close ( ) ;
135+ KinectSensor = null ;
136+
137+ // Mark as not initialized
138+ if ( unInitialize )
139+ IsInitialized = false ;
140+ }
141+
136142 private bool InitKinect ( )
137143 {
138144 if ( ( KinectSensor = KinectSensor . GetDefault ( ) ) is null ) return false ;
139145
140146 try
141147 {
148+ try
149+ {
150+ // Try to open the kinect sensor
151+ KinectSensor . Open ( ) ; // Open 0th
152+ Thread . Sleep ( 500 ) ;
153+
154+ // First try to de-init the sensor
155+ ShutdownInternal ( false ) ;
156+ Thread . Sleep ( 500 ) ;
157+ }
158+ catch
159+ {
160+ // ignored
161+ }
162+
142163 // Try to open the kinect sensor
143164 KinectSensor . Open ( ) ; // Open 1st
144165 for ( var i = 0 ; i < 20 ; i ++ )
You can’t perform that action at this time.
0 commit comments