简体   繁体   English

使用VBO时EXC_BAD_ACCESS

[英]EXC_BAD_ACCESS when using VBO

I've made some rendering with out using VBO. 我已经使用VBO进行了一些渲染。 Now i want to add VBO for more complex rendering. 现在,我想添加VBO以进行更复杂的渲染。 I'm just creating a VBO now, keeping the old rendering as it was and i render nothing with VBO now. 我现在只是创建一个VBO,保持原来的渲染不变,而现在我不使用VBO渲染任何东西。 Here is the code: 这是代码:

GLuint bufId;
glGenBuffers(1, &bufId);
glBindBuffer(type, bufId);
glBufferData(type, size, 0, GL_STATIC_DRAW);
//size = 100000;

That's the only code about VBO. 那是关于VBO的唯一代码。 But if the last stroke is not commented then i get EXC_BAD_ACCESS in old rendering when drawing GL_TRIANGLE_STRIP . 但是,如果没有对最后的笔触进行注释,则在绘制GL_TRIANGLE_STRIP时,我会在旧渲染中得到GL_TRIANGLE_STRIP I've put glGetError() before this bad access and it returns 0. What is the problem? 我将glGetError()放在此错误的访问之前,它返回0。这是什么问题? thanks 谢谢

EXC_BAD_ACCESS means that you have tried to read or write to memory that hasn't been mapped to your process. EXC_BAD_ACCESS意味着您试图读取或写入尚未映射到进程的内存。

There are lots of ways this can happen, and there's no way that glGetError() will know about it. 发生这种情况的方式有很多种,而glGetError()对此一无所知。

I wrote this blog that tries to help you debug it. 我写了这个博客,试图帮助您调试它。 It was for iPhone, but everything in it applies to Mac apps as well. 它用于iPhone,但其中的所有内容也适用于Mac应用程序。

http://loufranco.com/blog/files/Understanding-EXC_BAD_ACCESS.html http://loufranco.com/blog/files/Understanding-EXC_BAD_ACCESS.html

A key point is that EXC_BAD_ACCESS doesn't have to happen at the point of the bug -- the bug that caused it could have already run, and the bad access is happening in response -- the crash point may not be related at all. 关键是EXC_BAD_ACCESS不一定要在错误发生时发生-导致它的错误可能已经运行,并且错误的访问正在响应中发生-崩溃点可能根本不相关。 My blog goes through some debugging techniques to figure out where the problem really is. 我的博客通过一些调试技术来弄清楚问题出在哪里。 For example, it might have nothing to do with GL. 例如,它可能与GL无关。

In your code, what is the value of size and type ? 在您的代码中, sizetype的值是多少? It might have nothing to do with this. 这可能与此无关。

Some things to check for in all code that has run up to this point. 到现在为止,所有代码都需要检查一些事情。

  1. A double-free 一双免费
  2. Out-of-bounds reading/writing on arrays 数组的越界读取/写入
  3. Bad casts 坏演员

I've found the problem. 我发现了这个问题。 You have to unbind VBO if you want to draw with out it: 如果要绘制,则必须取消绑定VBO:

glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

after that everything worked 之后,一切正常

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

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