none
Why does function NuiImageStreamGetNextFrame() return E_INVALIDARG in multi-thread environment? RRS feed

  • Question

  • I wrote the simple code by infinite loop, which can run successfully.  [ while(true)... ]

    But when I wrote it in mulit-threads, this function returns E_INVALIDARG.

    My partial code is listed below:

     

    int _tmain ( int argc, _TCHAR* argv[]){
    
      HANDLE depth_stream = NULL;
    
      const NUI_IMAGE_FRAME* image_frame = NULL;
    
      mutex_handle = CreateMutex(NULL,FALSE,NULL);
    
      show_image_event_handle = CreateEvent(NULL,FALSE,FALSE,NULL); 
    
      is_running = true;
    
      thread_handle = CreateThread(NULL,0,
    
         (LPTHREAD_START_ROUTINE)ShowImageFrame, NULL, 0, NULL);
    
    
    
      cvNamedWindow("Depth", CV_WINDOW_AUTOSIZE);
    
    
    
      //Start: Initialize your kinect with depth camera
    
      hr = NuiInitialize(NUI_INITIALIZE_FLAG_USES_COLOR | NUI_INITIALIZE_FLAG_USES_DEPTH);
    
      if ( FAILED(hr) ) {
    
        printf("Fail to open device!\n");
    
        exit(1);
    
      }
    
      PBYTE depth32_data = (PBYTE) malloc(320*240*3*sizeof(BYTE));
    
    
    
      depth32 = cvCreateImage(cvSize(320, 240), IPL_DEPTH_8U, 3);
    
      int low,high;
    
      while ( is_running ) {
    
    	hr = NuiImageStreamGetNextFrame(depth_stream,0,&image_frame);
    
    
    
        if ( hr == E_NUI_FRAME_NO_DATA ) 
    
          continue;
    
    	else if ( FAILED(hr) ) break;
          ... ...
    
    


    When it runs at "hr = NuiImageStreamGetNextFrame(depth_stream,0,&image_frame);", this function returns E_INVALIDARG...

    Anyone can help?

    Thanks!!!

     


    "When you fall in love with CODING..."
    Saturday, October 8, 2011 8:14 AM

Answers

  • -2097086463 is 0x83010001, which is E_NUI_FRAME_NO_DATA, defined in MSR_NuiApi.h. It just means that an image frame isn't yet ready. This can happen if you call NuiImageStreamGetNextFrame too quickly after initialization, or too rapidly in succession. You can avoid this by passing a larger wait timeout value to NuiImageStreamGetNextFrame in the second parameter. E.g.: if you're passing zero milliseconds as the second parameter, consider passing 100 instead. It should return in 30 milliseconds or so, when data arrives (30 frames are delivered per second).

    Otherwise, if you don't want a long wait timeout, this is an expected error return value that you should handle.

    Eddy


    I'm here to help
    Monday, October 17, 2011 8:11 AM

All replies

  • I forgot to add function NuiImageStreamOpen...


    "When you fall in love with CODING..."
    Saturday, October 8, 2011 1:48 PM
  • Are you saying that adding NuiImageStreamOpen fixed your problem, or are you still having problem?

    Eddy


    I'm here to help
    Monday, October 10, 2011 8:12 PM
  • Hi Eddy,

    I am having a similar problem, I my return value from NuiImageStreamGetNextFrame is -2097086463 . But from the messages in the console and return value from NuiImageStreamOpen it looks like there was no problem initializing. Messages in console

    "Attempting to open \\?\USB#VID_045E&PID_02AE#B003612
    1-EF5E-00C04F2D728B}\00
    KinWinDeviceName = (\\?\USB#VID_045E&PID_02AE#B00361
    D1-EF5E-00C04F2D728B}\00\PIPE01)
    KinectCamera_OpenStreamEndpoint Opened successfully.
    KinWinDeviceName = (\\?\USB#VID_045E&PID_02AE#B00361
    D1-EF5E-00C04F2D728B}\00\PIPE00)
    KinectCamera_OpenStreamEndpoint Opened successfully."

    Could there be someother reason why NuiImageStreamGetNextFrame is failing?

    Thanks

    Archioliis

    Friday, October 14, 2011 9:51 PM
  • -2097086463 is 0x83010001, which is E_NUI_FRAME_NO_DATA, defined in MSR_NuiApi.h. It just means that an image frame isn't yet ready. This can happen if you call NuiImageStreamGetNextFrame too quickly after initialization, or too rapidly in succession. You can avoid this by passing a larger wait timeout value to NuiImageStreamGetNextFrame in the second parameter. E.g.: if you're passing zero milliseconds as the second parameter, consider passing 100 instead. It should return in 30 milliseconds or so, when data arrives (30 frames are delivered per second).

    Otherwise, if you don't want a long wait timeout, this is an expected error return value that you should handle.

    Eddy


    I'm here to help
    Monday, October 17, 2011 8:11 AM
  • HI Eddy,

    I am trying to do some coding as well with the kinect, i have a similar problem to that stated above however my delay is currently 500 ms , so i do not think that this is my problem. I decided to display what my hr is when it entered the check if FAILED condition and I am getting an error code:            -2147024809 which indicates that something is wrong with my HRESULT hr= NuiImageStreamGetNextFrame(phStreamHandle,500,&pImageFrame); 

    Can you tell me what this error code means and how I can fix it please. Also as I am  new to programming can you tell me what is the procedure for figuring out these error codes the next time I encounter one. I checked some of the header files to see where they are defined but I did not see this specific error code. For example I looked at msr_nuiapi.h as well as WinError.h but to no avail. 

     

    Thank you very much. looking forward to you response. 

    Friday, October 28, 2011 2:55 PM