1

Hello, I get a NullReferenceException when running this:

void newSensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
    {
        Skeleton first = GetFirstSkeleton(e);
        if (first == null)
        {
            return;
        }
        /**
         * @TODO
         * obsluzyc wyjatek null reference na wypadek gdy gubi szkielet
         */ 
        long timestamp = e.OpenSkeletonFrame().Timestamp;

it is in the line of long timestamp

It occurse while 10-15 seconds if same action. For example I'm logging some data standing still. I log them in every frame. After few seconds I get the NullReferenceException.

What is the problem?

Liam McInroy
  • 4,339
  • 5
  • 32
  • 53
Fixus
  • 4,631
  • 10
  • 38
  • 67

1 Answers1

1

Ok so I fouund answer for my problem. It is very simple.

Whe my system/machine is overloaded or it slows down from any other reason frames ain`t analyzed as fast as they sould. That whey when this lag occurs I can't open a frame. Thats why I get null.

Bellow solution of the problem

bool haveSkeletonData = false;
using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
{
if (skeletonFrame != null)
{
    if ((this.skeletonData == null) || (this.skeletonData.Length != skeletonFrame.SkeletonArrayLength))
    {
        this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength];
    }
    skeletonFrame.CopySkeletonDataTo(skeletonData);
    haveSkeletonData = true;
}
else
{
    haveSkeletonData = false;
}
}

if (haveSkeletonData)
{
   // here i can put code that is using my timestamp 
}

That way I'll be safe from null and I'll be able to use my timestamp as I need to :)

Fixus
  • 4,631
  • 10
  • 38
  • 67