Skip to content

Commit

Permalink
Kinect init bandaid try no.1
Browse files Browse the repository at this point in the history
  • Loading branch information
KimihikoAkayasaki committed Jan 6, 2024
1 parent 51801ba commit b2bbc78
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions plugin_KinectOne/KinectOne.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,7 @@ public void Initialize()

public void Shutdown()
{
// BodyFrameReader is IDisposable
BodyFrameReader?.Dispose();
BodyFrameReader = null;

// Close the kinect sensor
KinectSensor?.Close();
KinectSensor = null;

// Mark as not initialized
IsInitialized = false;
ShutdownInternal();
}

public void Update()
Expand All @@ -133,12 +124,42 @@ public void SignalJoint(int jointId)
// ignored
}

private void ShutdownInternal(bool unInitialize = true)
{
// BodyFrameReader is IDisposable
BodyFrameReader?.Dispose();
BodyFrameReader = null;

// Close the kinect sensor
KinectSensor?.Close();
KinectSensor = null;

// Mark as not initialized
if (unInitialize)
IsInitialized = false;
}

private bool InitKinect()
{
if ((KinectSensor = KinectSensor.GetDefault()) is null) return false;

try
{
try
{
// Try to open the kinect sensor
KinectSensor.Open(); // Open 0th
Thread.Sleep(500);

// First try to de-init the sensor
ShutdownInternal(false);
Thread.Sleep(500);
}
catch
{
// ignored
}

// Try to open the kinect sensor
KinectSensor.Open(); // Open 1st
for (var i = 0; i < 20; i++)
Expand Down

0 comments on commit b2bbc78

Please sign in to comment.