Why g_object_set throws an exception(vcruntime140.dll)?

#pragma comment(lib, "gstreamer-1.0.lib")
#pragma comment(lib, "gobject-2.0.lib")

#include <iostream>
#include <gst/gst.h>

int main( int argc, char *argv[] )
    gst_init( &argc, &argv );
    GstElement *source = nullptr;
    source = gst_element_factory_make("rtspsrc", "test_src");
    g_object_set(source, "location", "rtsp://");
    std::cout << "End";


After g_object_set(source, "location", "rtsp://"); an exception occurs: Exception thrown at 0x00007FFC26E9193C (vcruntime140.dll) in ConsoleApplication1.exe: 0xC0000005: Access violation reading location 0x0000000000008000. Function gst_element_factory_make returns not NULL. Why this exception throws?


1 Answer


According to the documentation found here, the issue is that the g_object_set is a variable-argument function that requires you to put in the sentinel argument (in this case, NULL).

g_object_set(source, "location", "rtsp://", NULL);

Not placing NULL means that the variable argument function does not know when the last argument is reached, thus is processing invalid data which causes the segmentation fault.

answered on Stack Overflow Dec 16, 2019 by PaulMcKenzie

User contributions licensed under CC BY-SA 3.0