首页 > 解决方案 > 为什么 g_object_set 会抛出异常(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://192.168.10.24:554");
    std::cout << "End";

}

g_object_set(source, "location", "rtsp://192.168.10.24:554");异常发生后: ConsoleApplication1.exe中0x00007FFC26E9193C(vcruntime140.dll)处抛出异常:0xC0000005:访问冲突读取位置0x0000000000008000。 函数gst_element_factory_make返回非 NULL。为什么会抛出这个异常?

标签: c++visual-studiogstreamer

解决方案


根据此处找到的文档,问题在于g_object_set是一个变量参数函数,需要您放入哨兵参数(在本例中为NULL)。

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

不放置NULL意味着可变参数函数不知道何时到达最后一个参数,因此正在处理导致分段错误的无效数据。


推荐阅读