none
More MultiSourceFrameReader AcquireLatestFrame AcquireFrame E_FAIL problems RRS feed

  • Question

  • I adopted the following code from the Coordinate Mapper sample. It typically works fine for a minute or two (sometimes longer). After that 

    hr = pDepthFrameReference->AcquireFrame(&pDepthFrame);

    starts returning E_FAIL and typically does not recover (at least not until I attach a debugger). The machine is super fast (coordinate mapper does easily 30fps).

    I noticed other people are asking similar questions but I did not see anything to resolve my problem. 

    Could you please suggest something?

    	IMultiSourceFrame* pMultiSourceFrame = NULL;
    	IDepthFrame* pDepthFrame = NULL;
    	IColorFrame* pColorFrame = NULL;
    	IBodyIndexFrame* pBodyIndexFrame = NULL;
    
    	HRESULT hr = _multiSourceFrameReader->AcquireLatestFrame(&pMultiSourceFrame);
    
    	if (SUCCEEDED(hr)) {
    		IDepthFrameReference* pDepthFrameReference = NULL;
    
    		hr = pMultiSourceFrame->get_DepthFrameReference(&pDepthFrameReference);
    		if (SUCCEEDED(hr)) {
    			hr = pDepthFrameReference->AcquireFrame(&pDepthFrame);
    		}
    
    		SafeRelease(pDepthFrameReference);
    	}
    
    	if (SUCCEEDED(hr)) {
    		IColorFrameReference* pColorFrameReference = NULL;
    
    		hr = pMultiSourceFrame->get_ColorFrameReference(&pColorFrameReference);
    		if (SUCCEEDED(hr)) {
    			hr = pColorFrameReference->AcquireFrame(&pColorFrame);
    		}
    
    		SafeRelease(pColorFrameReference);
    	}
    
    	if (SUCCEEDED(hr)) {
    		IBodyIndexFrameReference* pBodyIndexFrameReference = NULL;
    
    		hr = pMultiSourceFrame->get_BodyIndexFrameReference(&pBodyIndexFrameReference);
    		if (SUCCEEDED(hr)) {
    			hr = pBodyIndexFrameReference->AcquireFrame(&pBodyIndexFrame);
    		}
    
    		SafeRelease(pBodyIndexFrameReference);
    	}
    
    	if (SUCCEEDED(hr)) {
    
    		INT64 nDepthTime = 0;
    		IFrameDescription* pDepthFrameDescription = NULL;
    		int nDepthWidth = 0;
    		int nDepthHeight = 0;
    		UINT nDepthBufferSize = 0;
    		UINT16 *pDepthBuffer = NULL;
    
    		IFrameDescription* pColorFrameDescription = NULL;
    		int nColorWidth = 0;
    		int nColorHeight = 0;
    		ColorImageFormat imageFormat = ColorImageFormat_None;
    		UINT nColorBufferSize = 0;
    		RGBQUAD *pColorBuffer = NULL;
    
    		IFrameDescription* pBodyIndexFrameDescription = NULL;
    		int nBodyIndexWidth = 0;
    		int nBodyIndexHeight = 0;
    		UINT nBodyIndexBufferSize = 0;
    		BYTE *pBodyIndexBuffer = NULL;
    
    		// get depth frame data
    
    		hr = pDepthFrame->get_RelativeTime(&nDepthTime);
    
    		if (SUCCEEDED(hr)) {
    			hr = pDepthFrame->get_FrameDescription(&pDepthFrameDescription);
    		}
    
    		if (SUCCEEDED(hr)) {
    			hr = pDepthFrameDescription->get_Width(&nDepthWidth);
    		}
    
    		if (SUCCEEDED(hr)) {
    			hr = pDepthFrameDescription->get_Height(&nDepthHeight);
    		}
    
    		if (SUCCEEDED(hr)) {
    			hr = pDepthFrame->AccessUnderlyingBuffer(&nDepthBufferSize, &pDepthBuffer);
    		}
    
    		// get color frame data
    
    		if (SUCCEEDED(hr)) {
    			hr = pColorFrame->get_FrameDescription(&pColorFrameDescription);
    		}
    
    		if (SUCCEEDED(hr)) {
    			hr = pColorFrameDescription->get_Width(&nColorWidth);
    		}
    
    		if (SUCCEEDED(hr)) {
    			hr = pColorFrameDescription->get_Height(&nColorHeight);
    		}
    
    		if (SUCCEEDED(hr)) {
    			hr = pColorFrame->get_RawColorImageFormat(&imageFormat);
    		}
    
    		if (SUCCEEDED(hr)) {
    
    			if ((nColorWidth == cColorWidth) && (nColorHeight == cColorHeight)) {
    
    				width = nColorWidth;
    				height = nColorHeight;
    
    				if (imageFormat == ColorImageFormat_Bgra) {
    
    					hr = pColorFrame->AccessRawUnderlyingBuffer(&nColorBufferSize, reinterpret_cast<BYTE**>(&pColorBuffer));
    					if (SUCCEEDED(hr)) {
    						memcpy(rgba, pColorBuffer, nColorBufferSize);
    					}
    				}
    				else {
    					nColorBufferSize = cColorWidth * cColorHeight * sizeof(RGBQUAD);
    					hr = pColorFrame->CopyConvertedFrameDataToArray(nColorBufferSize, reinterpret_cast<BYTE*>(rgba), ColorImageFormat_Bgra);
    				}
    			}
    		}
    
    		// get body index frame data
    
    		if (SUCCEEDED(hr)) {
    			hr = pBodyIndexFrame->get_FrameDescription(&pBodyIndexFrameDescription);
    		}
    
    		if (SUCCEEDED(hr)) {
    			hr = pBodyIndexFrameDescription->get_Width(&nBodyIndexWidth);
    		}
    
    		if (SUCCEEDED(hr)) {
    			hr = pBodyIndexFrameDescription->get_Height(&nBodyIndexHeight);
    		}
    
    		if (SUCCEEDED(hr)) {
    			hr = pBodyIndexFrame->AccessUnderlyingBuffer(&nBodyIndexBufferSize, &pBodyIndexBuffer);
    		}
    
    		if (SUCCEEDED(hr)) {
    
    			if (pDepthBuffer && (nDepthWidth == cDepthWidth) && (nDepthHeight == cDepthHeight) &&
    				pBodyIndexBuffer && (nBodyIndexWidth == cDepthWidth) && (nBodyIndexHeight == cDepthHeight)) {
    
    				HRESULT hr = _coordinateMapper->MapColorFrameToDepthSpace(nDepthWidth * nDepthHeight, (UINT16*)pDepthBuffer, nColorWidth * nColorHeight, _depthCoordinates);
    
    				if (SUCCEEDED(hr)) {
    
    					memset(mask, 0, nColorWidth*nColorHeight);
    
    					for (int colorIndex = 0; colorIndex < (nColorWidth*nColorHeight); ++colorIndex) {
    
    						DepthSpacePoint p = _depthCoordinates[colorIndex];
    
    						// Values that are negative infinity means it is an invalid color to depth mapping so we
    						// skip processing for this pixel
    						if (p.X != -std::numeric_limits<float>::infinity() && p.Y != -std::numeric_limits<float>::infinity()) {
    
    							int depthX = static_cast<int>(p.X + 0.5f);
    							int depthY = static_cast<int>(p.Y + 0.5f);
    
    							if ((depthX >= 0 && depthX < nDepthWidth) && (depthY >= 0 && depthY < nDepthHeight)) {
    
    								BYTE player = pBodyIndexBuffer[depthX + (depthY * cDepthWidth)];
    
    								if (player >= 0 && player <= 5) {
    									mask[colorIndex] = 255;
    								}
    							}
    						}
    					}
    				}
    			}
    		}
    
    		SafeRelease(pDepthFrameDescription);
    		SafeRelease(pColorFrameDescription);
    		SafeRelease(pBodyIndexFrameDescription);
    	}
    
    	SafeRelease(pDepthFrame);
    	SafeRelease(pColorFrame);
    	SafeRelease(pBodyIndexFrame);
    	SafeRelease(pMultiSourceFrame);
    

    Tuesday, March 17, 2015 10:18 PM

All replies