问题
A week ago, we had a working project. The following worked, without a problem on my machine (Window 8 developing in VisualStudio 2010)
KinectSensor sensor = KinectSensor.KinectSensors[0];
public KinectController()
{
sensor.SkeletonFrameReady += runtime_SkeletonFrameReady;
sensor.ColorStream.Enable();
sensor.SkeletonStream.Enable();
sensor.Start();
}
This worked no problems. When my teammate pulled this down from an SVN, it broke, giving a null reference exception on ColorStream.Enable(). Deleting and adding the Microsoft.Kinect reference, for some reason, fixed it in the past, but now, it seems as though it is broken permanently. I ALWAYS throws an exception at this line. In debug, the ColorStream and SkeletonStream are null, even though it was clearly instantiated. Even doing
KinectSensor sensor;
public KinectController()
{
sensor = KinectSensor.KinectSensors[0];
sensor.SkeletonFrameReady += runtime_SkeletonFrameReady;
sensor.ColorStream.Enable();
sensor.SkeletonStream.Enable();
sensor.Start();
}
will throw the null reference exception. What is happening? Why is this throwing an exception? It broke just as we were ready to present it, which is disheartening to even program with Kinect again.
来源:https://stackoverflow.com/questions/17118753/kinectsensor-nullreferenceexception