Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenNI C# wrapper: WaitAnyUpdateAll timeout

Tags:

c#

openni

I'm currently working on a small project involving a Kinect with the OpenNI C# wrapper. For this project a depth, image and user node are created using an xml configuration file and the Context.CreateFromXmlFile method. A separate thread is started which does a very simple loop (based on the UserTracker.net example):

private void RunThread()
{
   while(true) 
   {
       try 
       {
           context.WaitAnyUpdateAll(); //context is an OpenNI context object. 
       }
       catch (Exception ex) 
       {
           Console.WriteLine(ex.ToString());
       }

       //process some data

   }
}

This works just fine for a while, until the image the camera receives doesn't change. After a short while the following exception is shown:

A timeout has occured when waiting for new data!
    at OpenNI.Context.WaitAnyUpdateAll()
    at <file described above>

After this exception is thrown all subsequent calls to context.WaitAnyUpdateAll will throw the same exception, regardless of what the input is. After a while the error message changes to:

OpenNI.StatusException: The server has disconnected!
    at OpenNI.Context.WaitAnyUpdateAll()
    at <file described above>

How can I deal with no new input using OpenNI? I understand that we get a timeout exception when no new data is available, but how can we recover from this exception?

like image 323
Tiddo Avatar asked Apr 22 '13 10:04

Tiddo


1 Answers

It turns out that the problem was that I didn't use an unsafe loop. It seems that WaitAnyUpdateAll requires to be run in an unsafe context, and I didn't do that here. Adding the unsafe keyword to the function definition solved the problem.

like image 194
Tiddo Avatar answered Oct 26 '22 17:10

Tiddo