C++ gstreamer pipeline overlay problems

I have a gstreamer pipeline which I am running with gst-launch to test out CUDA. This is the one I am using and it works fine:

(camera_v4l2_cuda:11182): GLib-GObject-WARNING **: 12:23:46.182: value "TRUE" of type 'gboolean' is invalid or out of range for property 'cuda-process' of type 'gboolean'
Now playing.
Running...
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected...
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 3264 x 2464 FR = 21.000000 fps Duration = 47619048 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 3264 x 1848 FR = 28.000001 fps Duration = 35714284 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1920 x 1080 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1640 x 1232 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1280 x 720 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1280 x 720 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: Running with following settings:
   Camera index = 0 
   Camera mode  = 5 
   Output Stream W = 1280 H = 720 
   seconds to Run    = 0 
   Frame Rate = 120.000005 
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
0:00:00.749757448 11182   0x7f84002350 ERROR                    omx gstomx.c:496:EventHandler:<nvoverlaysink-nvoverlaysink0> yuv420 got error: Insufficient resources (0x80001000)
NvxBaseWorkerFunction[2575] comp OMX.Nvidia.std.iv_renderer.overlay.yuv420 Error -2147479552 
0:00:00.749867193 11182   0x7f84002350 ERROR                    omx gstomx.c:496:EventHandler:<nvoverlaysink-nvoverlaysink0> yuv420 got error: Insufficient resources (0x80001000)
0:00:00.749948968 11182   0x558a842370 ERROR                    omx gstomx.c:268:gst_omx_component_handle_messages:<nvoverlaysink-nvoverlaysink0> yuv420 got error: Insufficient resources (0x80001000)
0:00:00.749990324 11182   0x558a842370 ERROR                    omx gstomx.c:268:gst_omx_component_handle_messages:<nvoverlaysink-nvoverlaysink0> yuv420 got error: Insufficient resources (0x80001000)
0:00:00.750018815 11182   0x558a842370 ERROR           omxvideosink gstomxvideosink.c:1397:gst_omx_video_sink_show_frame:<nvoverlaysink-nvoverlaysink0> Component in error state: Insufficient resources (0x80001000)
Error: Internal data stream error.
Returned, stopping playback

The code I am using is below, but I believe it is correct:

GMainLoop* loop;
    GstElement* pipeline, *source, *cuda, *output;
    GstBus* bus;
    GstCaps *argus_caps, *nviva_caps;
    gboolean link_ok;
    guint bus_watch_id;
    int ret;

    /* Initialisation */
    gst_init(&argc, &argv);
    loop = g_main_loop_new(NULL, FALSE);

    /* Create gstreamer elements */
    pipeline = gst_pipeline_new("cuda_gimbal");
    source   = gst_element_factory_make("nvarguscamerasrc", NULL);
    cuda  = gst_element_factory_make("nvivafilter", NULL);
    output  = gst_element_factory_make("nvoverlaysink", NULL);

    if(!pipeline || !source || !cuda || !output)
    {
        g_printerr("One element could not be created. Exiting.\n");
        return -1;
    }

    /* Set up the pipeline */
    g_object_set(G_OBJECT(cuda),
                 "cuda-process", "true",
                 "customer-lib-name", "libnvsample_cudaprocess.so",
                 NULL);
    g_object_set(G_OBJECT(output),
                 "display-id", "1", NULL);

    /* we add a message handler */
    bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
    bus_watch_id = gst_bus_add_watch(bus, bus_call, loop);
    gst_object_unref(bus);

    /* we add all elements into the pipeline */
    /* file-source | ogg-demuxer | vorbis-decoder | converter | alsa-output */
    gst_bin_add_many(GST_BIN(pipeline), source, cuda, output, NULL);

    // Add the caps.
    argus_caps = gst_caps_from_string("video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, format=(string)NV12, framerate=(fraction)30/1");
    if(argus_caps == NULL)
    {
        printf("FAILED.\n");
    }
    nviva_caps = gst_caps_from_string("video/x-raw(memory:NVMM), format=(string)NV12");
    if(nviva_caps == NULL)
    {
        printf("FAILED.\n");
    }
    
    link_ok = gst_element_link_filtered(source, cuda, argus_caps);
    //gst_caps_unref(argus_caps);
    if(!link_ok)
    {
        printf("Error: could not link argus_caps.\n");
        goto gst_exit;
    }
    
    link_ok = gst_element_link_filtered(cuda, output, nviva_caps);
    //gst_caps_unref(nviva_caps);
    if(!link_ok)
    {
        printf("Error: could not link nviva_caps.");
        goto gst_exit;
    }

    /* we link the elements together */
    gst_element_link_many(source, cuda, output, NULL);

    /* Set the pipeline to "playing" state*/
    g_print("Now playing.\n");
    gst_element_set_state(pipeline, GST_STATE_PLAYING);
    ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
    if(ret == GST_STATE_CHANGE_FAILURE)
    {
        g_printerr ("Unable to set the pipeline to the playing state.\n");
        goto gst_exit;
    }

    /* Iterate */
    g_print("Running...\n");
    g_main_loop_run(loop);
    // Or you can use gst_bus_timed_pop_filtered()
    // https://gstreamer.freedesktop.org/documentation/tutorials/basic/concepts.html?gi-language=c

    /* Out of the main loop, clean up nicely */
    g_print("Returned, stopping playback\n");
    gst_element_set_state(pipeline, GST_STATE_NULL);

gst_exit:
    g_print("Deleting pipeline\n");
    gst_object_unref(GST_OBJECT(pipeline));
    g_source_remove(bus_watch_id);
    g_main_loop_unref(loop);

What is the cause of the error? The pipeline works fine with gst-launch. Thanks.

gstomx.c:496:EventHandler: yuv420 got error: Insufficient resources

Hi,
Not sure if it help but please apply this prebuilt lib for a try:
Jetson/L4T/r32.5.x patches - eLinux.org
[camera] 3rdparty application fails to open with USB camera

And may also try to launch a pipeline through gst_parse_launch(). Here is a sample:
GStreamer freeze when using qtmux and NVIDIA-accelerated h264/h265 encoding - #7 by DaneLLL

Yes, gst_parse_launch() works fine. I was hoping to get the more complicated pipeline working.