none
BodyFrameReader.AcquireLatestFrame always returns null RRS feed

  • Question

  • I'm using the kinect plugin for Unity to animate a body. I'm using the code below, but BodyFrameReader.AcquireLatestFrame() always returns null:

    private KinectSensor _sensor;
    private BodyFrameReader _reader;
    
    void Start()
    {
    	_sensor = KinectSensor.GetDefault();
    
    	if (_sensor != null)
    	{
    		_reader = _sensor.BodyFrameSource.OpenReader();
    
    		if (!_sensor.IsOpen)
    		{
    			_sensor.Open();
    		}
    	}
    }
    
    void Update()
    {
    	if (_reader != null)
    	{
    		var frame = _reader.AcquireLatestFrame(); //This always returns null
    
    		if (frame == null)
    		{
    			Debug.Log("No frame available");
    			return;
    		}
    	}
    }

    Am I forgetting something? The WPF samples and Unity samples all work.

    EDIT: Did some more debugging, and I can see that I get one frame, and after that AcquireLatestFrame is always null. In BodyFrameReader.cs it calls the native method Windows_Kinect_BodyFrameReader_AcquireLastestFrame(_pnative). Which returns the nullptr.



    • Edited by Saticmotion Tuesday, March 10, 2015 12:06 PM
    Tuesday, March 10, 2015 11:06 AM

Answers

  • you didn't call dispose on the frame. The runtime will not give you anymore frames until you release the one that you acquired. To be safe using the "using()" pattern demonstrated in the samples to ensure you are correctly disposing objects.

    Carmine Sirignano - MSFT

    Tuesday, March 10, 2015 6:45 PM

All replies

  • you didn't call dispose on the frame. The runtime will not give you anymore frames until you release the one that you acquired. To be safe using the "using()" pattern demonstrated in the samples to ensure you are correctly disposing objects.

    Carmine Sirignano - MSFT

    Tuesday, March 10, 2015 6:45 PM
  • Thanks for the answer!

    I did try that after my original post, but forgot to update my thread. I tried both using() and regular Dispose() but didn't change anything.

    I've now imported my scripts and prefabs into another project, of which I was sure it was working with the Kinect, and now my scripts work without issues. Maybe there was a bad dll or something in my project? But would that explain getting that first frame? In any case, I can get to work again, so I'll mark this resolved.

    Wednesday, March 11, 2015 8:30 AM