c++ - 为什么 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。为什么会抛出这个异常?
解决方案
根据此处找到的文档,问题在于g_object_set
是一个变量参数函数,需要您放入哨兵参数(在本例中为NULL
)。
g_object_set(source, "location", "rtsp://192.168.10.24:554", NULL);
不放置NULL
意味着可变参数函数不知道何时到达最后一个参数,因此正在处理导致分段错误的无效数据。
推荐阅读
- macos - 如何在 Visual Studio Code for Mac 中查看 NuGet 包实现源?
- node.js - 如何查询 mongoDB 以查看匹配记录是否存在,以及是否返回它以进行更新
- python - 如何从另一个 Screen 类访问 Kivy 类的值?
- algorithm - 在图上找到一个正的简单 st 路径是 NP 完全的?
- ruby-on-rails - 在 Heroku(Rails)上新建后“无法验证 CSRF 令牌的真实性”
- c# - 关闭 SqlConnection 不会关闭关闭 SQL 上的事务
- tensorflow - 如何在 keras-tuner 中为超参数训练选择优化器和学习率
- python - 如何使用带有多个子图的 matplotlib 吸引人地排列标题和轴标签等图形和文本?
- java - 值按单个字符显示
- c# - 如何让我的敌人名单射击c#