NvBufSurfTransform error

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU)
• DeepStream Version
• JetPack Version (valid for Jetson only)
• TensorRT Version
• NVIDIA GPU Driver Version (valid for GPU only)
• Issue Type( questions, new requirements, bugs)
• How to reproduce the issue ? (This is for bugs. Including which sample app is using, the configuration files content, the command line used and other details for reproducing)
• Requirement details( This is for new requirement. Including the module name-for which plugin or for which sample application, the function description)

Hi Nvidia, please help. I am trying to create a sample to work with NvBufSurfTransform API. The function call works well in gstdsexample plugin but failed in this sample code. Please correct me if I am using it wrong way.
The code failed at line 62 and i got segmentation faultmain.cpp (1.9 KB)

I am testing this code in DeepStream 5.1 x86 docker.
Compile: nvcc main.cpp -I /opt/nvidia/deepstream/deepstream/sources/includes/ -L /opt/nvidia/deepstream/deepstream/lib/ -lnvbufsurface -lnvbufsurftransform
Run: LD_LIBRARY_PATH=/opt/nvidia/deepstream/deepstream/lib/ ./a.out

//
// Created by hunglx on 03/08/2021.
//

#include <iostream>
#include <cuda_runtime.h>
#include <nvbufsurftransform.h>

using namespace std;

int width = 1280;
int height = 720;

int main() {

  cudaSetDevice(0);

  NvBufSurfTransformConfigParams session_params;
  session_params.gpu_id = 0;
  session_params.compute_mode = NvBufSurfTransformCompute_GPU;
  NvBufSurfTransformSetSessionParams(&session_params);


  NvBufSurface *surface_0;
  NvBufSurface *surface_1;
  int batch_size = 1;

  NvBufSurfaceCreateParams create_params;
  create_params.gpuId = 0;
  create_params.width = width;
  create_params.height = height;
  create_params.size = 0;
  create_params.colorFormat = NVBUF_COLOR_FORMAT_RGBA;
  create_params.layout = NVBUF_LAYOUT_PITCH;

  create_params.memType = NVBUF_MEM_DEFAULT;
  NvBufSurfaceCreate(&surface_0, batch_size, &create_params);

  create_params.memType = NVBUF_MEM_CUDA_UNIFIED;
  NvBufSurfaceCreate(&surface_1, batch_size, &create_params);

  surface_0->numFilled = 1;
  surface_1->numFilled = 1;

  NvBufSurfTransformParams transform_params;
  transform_params.src_rect = new NvBufSurfTransformRect[batch_size];
  transform_params.src_rect[0].top = 0;
  transform_params.src_rect[0].left = 0;
  transform_params.src_rect[0].width = width;
  transform_params.src_rect[0].height = height;

  transform_params.dst_rect = new NvBufSurfTransformRect[batch_size];
  transform_params.dst_rect[0].top = 0;
  transform_params.dst_rect[0].left = 0;
  transform_params.dst_rect[0].width = width;
  transform_params.dst_rect[0].height = height;

  transform_params.transform_flag = NVBUFSURF_TRANSFORM_CROP_SRC | NVBUFSURF_TRANSFORM_CROP_DST | NVBUFSURF_TRANSFORM_FILTER;
  transform_params.transform_flip = NvBufSurfTransform_None;
  transform_params.transform_filter = NvBufSurfTransformInter_Default;

  auto err = NvBufSurfTransform(surface_0, surface_1, &transform_params);
  cout << "err: " << err << endl;
}

Please refer to DeepStream SDK FAQ - #18 by bcao