AcquireLatestFrame frequently fails when using event model to query depth AND color frames simultaneously RRS feed

  • Question

  • In my application I need to process depth and color frames in pairs, so I need to grab frames from the 2 streams simultaneously. I started with the "Depth Basics D2D" and "Color Basics D2D" examples from the SDK, deleted the D2D part, added event subscription at initialization:

    // In class DepthBasics
    WAITABLE_HANDLE waitable_handle;
    hr = m_pDepthFrameReader->SubscribeFrameArrived(&waitable_handle);
    m_hNextDepthFrameEvent = reinterpret_cast<HANDLE>(waitable_handle);
    // In class ColorBasics
    WAITABLE_HANDLE waitable_handle;
    hr = m_pColorFrameReader->SubscribeFrameArrived(&waitable_handle);
    m_hNextColorFrameEvent = reinterpret_cast<HANDLE>(waitable_handle);

    And put the two classes into the same application, wrapped them with a KinectManager:

    // In definition
    HANDLE m_events[2];
    // In implementation
    m_events[0] = m_depthBasics->m_hNextDepthFrameEvent;
    m_events[1] = m_colorBasics->m_hNextColorFrameEvent;

    And I have one separate thread to wait for the 2 events, acquire frames, and put them into buffers:

    while (true)
        if (WaitForMultipleObjects(2, m_KinectManager.m_events, TRUE, INFINITE) == WAIT_OBJECT_0)
            // This calls AcquireLatestFrame on both DepthBasics and ColorBasics

    Actually at first I only had depth frames to process and it worked fine. Then I added color frames, and the rate at which I can query frames from both streams drops significantly. By printing to the console, I find that, frequently, both events are fired, but one or both of the AcquireLatestFrame calls fail.

    As you can see I am using the native API in C++. Am I doing this wrong? What should I do?

    Wednesday, June 8, 2016 2:17 AM


  • Hello,

    It is probably a synchronization issue. If you need to acquire multiple frames simultaneously you should consider using MultiSourceFrameReader.

    In your case with a bitmask like this:

     hr = m_pKinectSensor->OpenMultiSourceFrameReader(
                    FrameSourceTypes::FrameSourceTypes_Depth | FrameSourceTypes::FrameSourceTypes_Color,
    For inspiration how to implement application using this reader I suggest you to take a look at CoordinateMappingBasics sample from Kinect 2 SDK

    • Proposed as answer by Jan Marcincin Wednesday, June 8, 2016 7:26 AM
    • Marked as answer by MacMillan333 Wednesday, June 8, 2016 7:44 AM
    Wednesday, June 8, 2016 7:25 AM