简体   繁体   English

调用glBufferData()时出现随机的“未处理的异常”

[英]Random “unhandled exception” when called glBufferData()

I have some OpenGL code that runs perfectly, but every now and then (about every fifth time or so) when I try to launch the program, it crashes with unhandled exception: 我有一些运行良好的OpenGL代码,但是每当我尝试启动该程序时(大约每五次左右),它就会崩溃,并带有未处理的异常:

Unhandled exception at 0x5CE5F86E (atioglxx.dll) in Main.exe: 0xC0000005:
Access violation reading location 0x07388000.

The line it points to is just a simple glBufferData() call: 它指向的行只是一个简单的glBufferData()调用:

glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_indices.size() * sizeof(GLuint), &m_indices[0], GL_STATIC_DRAW);

Is there something I can do about it? 有什么我可以做的吗? Or is it a graphics driver problem? 还是图形驱动程序问题? I do have the latest drivers installed (the card is Radeon 290X). 我确实安装了最新的驱动程序(卡为Radeon 290X)。 The crash is really inconsistent; 飞机坠毁确实是前后矛盾的。 without any changes, if I just keep launching the program, it usually takes a couple of times before it does this. 如果不做任何更改,如果我继续启动该程序,则通常需要花费几次时间才能执行此操作。

From your comments it seems that you have a type size mismatch, change your call to 从您的评论看来,您的字体大小不匹配,请更改为

lBufferData(
  GL_ELEMENT_ARRAY_BUFFER, 
  m_indices.size() * sizeof m_indices[0], 
  m_indices.data(),
  GL_STATIC_DRAW
);

You could also use a small helper function like the following to cut down on the crud (which helps avoid bugs like this) 您还可以使用如下所示的小型辅助函数来减少负担(这有助于避免此类错误)

template<typename T, typename Allocator>
size_t sizeof_vec(std::vector<T, Allocator> const& v)
{
  return v.size() * sizeof(T);
}

lBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof_vec(m_indices), m_indices.data(), GL_STATIC_DRAW);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM