none
kinect deadlock when shutdown with function INuiSensor::NuiShutdown or NuiShutdown in C++ RRS feed

  • Question

  • Hi,

    I'm using kinect sdk 1.6 and I'm finding an issue when trying to change the resolution of the rgb camera. To change the resolution I think I should turn off the kinect with NuiShutDown then re-inizialize it with the new resolution. The problem is that the program deadlocks when i call the NiuShutDown. 

    This is the code that I use for inizializing the kinect

        INuiSensor * pNuiSensor;
        HRESULT hr;
    	
        int iSensorCount = 0;
        hr = NuiGetSensorCount(&iSensorCount);
        if (FAILED(hr))
        {
            return hr;
        }
    
            // Initialize the Kinect and specify that we'll be using color
    
        // Look at each Kinect sensor
        for (int i = 0; i < iSensorCount; ++i)
        {
            // Create the sensor so we can check status, if we can't create it, move on to the next
            hr = NuiCreateSensorByIndex(i, &pNuiSensor);
            if (FAILED(hr))
            {
                continue;
            }
    
            // Get the status of the sensor, and if connected, then we can initialize it
            hr = pNuiSensor->NuiStatus();
            if (S_OK == hr)
            {
                m_pNuiSensor = pNuiSensor;
                break;
            }
    
            // This sensor wasn't OK, so release it since we're not using it
            pNuiSensor->Release();
        }
    
        if (NULL != m_pNuiSensor)
        {
            // Initialize the Kinect and specify that we'll be using color
            hr = m_pNuiSensor->NuiInitialize(NUI_INITIALIZE_FLAG_USES_COLOR); 
            if (SUCCEEDED(hr))
            {
                // Create an event that will be signaled when color data is available
                m_hNextColorFrameEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    
                // Open a color image stream to receive color frames
                hr = m_pNuiSensor->NuiImageStreamOpen(
                    NUI_IMAGE_TYPE_COLOR,
                    NUI_IMAGE_RESOLUTION_640x480,
                    0,
                    1,
                    m_hNextColorFrameEvent,
                    &m_pColorStreamHandle);
            }
        }
    
        if (NULL == m_pNuiSensor || FAILED(hr))
        {
            MessageBox("No ready Kinect found!");
            return E_FAIL;
        }
    
        return hr;

    and this is the code for changing the resolution

    	HRESULT hr;
    
    	this->m_pNuiSensor->NuiShutdown();
    
        // Initialize the Kinect and specify that we'll be using color
        hr = this->m_pNuiSensor->NuiInitialize(NUI_INITIALIZE_FLAG_USES_COLOR); 
        if (SUCCEEDED(hr))
        {
            // Create an event that will be signaled when color data is available
            m_hNextColorFrameEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    
    	hr = this->m_pNuiSensor->NuiImageStreamOpen(
    					NUI_IMAGE_TYPE_COLOR,
    					NUI_IMAGE_RESOLUTION_1280x960,
    					0,
    					1,
    					m_hNextColorFrameEvent,
    					&m_pColorStreamHandle);
    
        }
    
        if (FAILED(hr))
        {
            MessageBox("No restart!");
            return hr;
        }

    thank you very much.

    NilusI.

    Monday, January 28, 2013 5:03 PM

Answers

  • Now it's working! 

    This morning I turned on the PC and I tried again with the same code and now it's working. Maybe yestarday, while working with the kinect I currupted it and restarting the PC solved the problems.


    Tuesday, January 29, 2013 8:46 AM