EXC_BAD_ACCESS when using VBO
I've made some rendering with out using VBO. Now i want to add VBO for more complex rendering. I'm just creating a VBO now, keeping the old rendering as it was and i render nothing with VBO now. 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. But if the last stroke is not commented then i get EXC_BAD_ACCESS in old开发者_开发问答 rendering when drawing GL_TRIANGLE_STRIP
. I've put glGetError()
before this bad access and it returns 0. What is the problem? thanks
EXC_BAD_ACCESS means that you have tried to read or write to memory that hasn't been mapped to your process.
There are lots of ways this can happen, and there's no way that glGetError() will know about it.
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.
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. 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.
In your code, what is the value of size
and type
? It might have nothing to do with this.
Some things to check for in all code that has run up to this point.
- A double-free
- Out-of-bounds reading/writing on arrays
- Bad casts
I've found the problem. You have to unbind VBO if you want to draw with out it:
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
after that everything worked
精彩评论