Segfault when swapping pointer to surface data

Hi @cbstryker ,
There is similar code in /opt/nvidia/deepstream/deepstream/sources/gst-plugins/gst-dsexample/gstdsexample.cpp

On Jetson, I added below change in the file and can write the data into test.png correctly.
This indicates that the dsexample->inter_buf->surfaceList[0].mappedAddr.addr[0] is CPU accessiable on Jetson.

Could you double check your code based on this dsexample code?

  /* Map the buffer so that it can be accessed by CPU */
  if (NvBufSurfaceMap (dsexample->inter_buf, 0, 0, NVBUF_MAP_READ) != 0){
    goto error;
  }

  /* Cache the mapped data for CPU access */
  NvBufSurfaceSyncForCpu (dsexample->inter_buf, 0, 0);

  /* Use openCV to remove padding and convert RGBA to BGR. Can be skipped if
   * algorithm can handle padded RGBA data. */
  in_mat =
      cv::Mat (dsexample->processing_height, dsexample->processing_width,
      CV_8UC4, dsexample->inter_buf->surfaceList[0].mappedAddr.addr[0],
      dsexample->inter_buf->surfaceList[0].pitch);

#if (CV_MAJOR_VERSION >= 4)
  cv::cvtColor (in_mat, *dsexample->cvmat, cv::COLOR_RGBA2BGR);
#else
  cv::cvtColor (in_mat, *dsexample->cvmat, CV_RGBA2BGR);
#endif

+      static int cnt = 0;
+      if (cnt++ == 20)
+            cv::imwrite ("test.png", in_mat);

  if (NvBufSurfaceUnMap (dsexample->inter_buf, 0, 0)){
    goto error;
  }