当我尝试运行我的骨骼跟踪代码来测试我添加的以下代码行时,它会因错误而崩溃。
void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
{
if (closing)
{
return;
}
//Get a skeleton
Skeleton first = GetFirstSkeleton(e);
if (first == null)
{
return;
}
using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
{
//if (skeletonFrame == null)
//{
// return;
//}
this.recordStream = new MemoryStream(100);
KinectRecorder Recorder = new KinectRecorder(KinectRecordOptions.Skeletons, recordStream);
if (skeletonFrame != null)
{
this.Recorder.Record(skeletonFrame);
}
//StartRecord
// Skeleton[] skeletonData = this.Recorder.Record(skeletonFrame);
}
// some more stuff
}
我正在调用 Kinect 工具箱中可用的记录功能。
错误是:未处理 System.NullReferenceException ....... Message=Object reference not set to an instance of an object。..... Source=SkeletalTracking
更新:如果我将初始化移动到与记录器调用相同的函数中。