Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top