title: MapColorFrameToDepthFrame (Unhandled Exception, Access Violation)
body: <p>I tried to align the depth image with color image using the MapColorFrameToDepthFrame function but there is a problem at this line of code (Unhandled Exception, Access Violation):</p>
  
  <pre><code>pMapper-&gt;MapColorFrameToDepthFrame(
          NUI_IMAGE_TYPE_COLOR,
          NUI_IMAGE_RESOLUTION_640x480,
          NUI_IMAGE_RESOLUTION_640x480,
          640 * 480, 
          (NUI_DEPTH_IMAGE_PIXEL*)LockedRect.Pitch,
          640 * 480, 
          depthPoints);
  </code></pre>
  
  <p>Here is the code of the Nui_GotDepthAlert:</p>
  
  <pre><code>bool CSkeletalViewerApp::Nui_GotDepthAlert( ){
  NUI_IMAGE_FRAME imageFrame;
  bool processedFrame = true;
  
  HRESULT hr = m_pNuiSensor-&gt;NuiImageStreamGetNextFrame(
      m_pDepthStreamHandle,
      0,
      &amp;imageFrame );
  
  if ( FAILED( hr ) )
  {
      return false;
  }
  
  m_depthTimeStamp = imageFrame.liTimeStamp;
  
  INuiFrameTexture * pTexture = imageFrame.pFrameTexture;
  NUI_LOCKED_RECT LockedRect;
  pTexture-&gt;LockRect( 0, &amp;LockedRect, NULL, 0 );
  if ( 0 != LockedRect.Pitch )
  {
      INuiCoordinateMapper* pMapper;
      NUI_DEPTH_IMAGE_POINT* depthPoints;
  
      depthPoints = new NUI_DEPTH_IMAGE_POINT[640 * 480];
      m_pNuiSensor-&gt;NuiGetCoordinateMapper(&amp;pMapper);
  
      //NUI_DEPTH_IMAGE_PIXEL* pdepthpixel = (NUI_DEPTH_IMAGE_PIXEL*)LockedRect.Pitch;
  
      pMapper-&gt;MapColorFrameToDepthFrame(
          NUI_IMAGE_TYPE_COLOR,
          NUI_IMAGE_RESOLUTION_640x480,
          NUI_IMAGE_RESOLUTION_640x480,
          640 * 480, 
          (NUI_DEPTH_IMAGE_PIXEL*)LockedRect.Pitch,
          640 * 480, 
          depthPoints);
  
      //memcpy(m_depthD16, LockedRect.pBits, LockedRect.size);
  
      DWORD frameWidth, frameHeight;
  
      NuiImageResolutionToSize( imageFrame.eResolution, frameWidth, frameHeight );
  
      // draw the bits to the bitmap
      BYTE * rgbrun = m_depthRGBX;
      const USHORT * pBufferRun = (const USHORT *)LockedRect.pBits;
  
      depthData = (USHORT *)LockedRect.pBits;
  
  
      // end pixel is start + width*height - 1
      const USHORT * pBufferEnd = pBufferRun + (frameWidth * frameHeight);
  
      assert( frameWidth * frameHeight * g_BytesPerPixel &lt;= ARRAYSIZE(m_depthRGBX) );
      USHORT depth;
      USHORT* depth1=(USHORT *)LockedRect.pBits;
      USHORT realDepth;
      while ( pBufferRun &lt; pBufferEnd )//&amp;&amp; pDepth &lt; depthEnd)
      {
          /**depthValues = pDepth-&gt;depth;
          depthValues++;*/
  
          //USHORT depth     = *pBufferRun;
          depth     = *pBufferRun;
          USHORT realDepth = NuiDepthPixelToDepth(depth);
          USHORT player    = NuiDepthPixelToPlayerIndex(depth);
  
          // transform 13-bit depth information into an 8-bit intensity appropriate
          // for display (we disregard information in most significant bit)
          BYTE intensity = static_cast&lt;BYTE&gt;(~(realDepth &gt;&gt; 4));
  
          // tint the intensity by dividing by per-player values
          *(rgbrun++) = intensity &gt;&gt; g_IntensityShiftByPlayerB[player];
          *(rgbrun++) = intensity &gt;&gt; g_IntensityShiftByPlayerG[player];
          *(rgbrun++) = intensity &gt;&gt; g_IntensityShiftByPlayerR[player];
  
          // no alpha information, skip the last byte
          ++rgbrun;
  
          ++pBufferRun;
      }
  
  
  
      m_pDrawDepth-&gt;Draw( m_depthRGBX, frameWidth * frameHeight * g_BytesPerPixel );
  
  
  }
  else
  {
      processedFrame = false;
      OutputDebugString( L"Buffer length of received texture is bogus\r\n" );
  }
  
  pTexture-&gt;UnlockRect( 0 );
  
  if(m_pDepthStreamHandle != NULL)
      m_pNuiSensor-&gt;NuiImageStreamReleaseFrame( m_pDepthStreamHandle, &amp;imageFrame );  
  
  
  
  
  return processedFrame;
  </code></pre>
  
  <p>}</p>
  
  <p>Could someone tell me how to fix this problem?</p>
  
  <p>Thank you</p>