c++ - OpenGL VBO EXC_BAD_ACCESS Crash -
i want start using vbos render models, i'm running error haven't been able resolve. i've seen occurs when people forget unbind buffer, far can tell i'm doing correctly. i'll spare print statements have determined there opengl error 1281 after call
glbindbuffer(gl_array_buffer, _vboid);
in drawme() function. guess 1281 indicates bad value... don't know means here. if can see going wrong, please enlighten me.
i initialize _vboid 0 in construction of model object.
_vboid = 0;
then :
void model::genbuffers() { if (_vboid == 0){ glgenbuffers(1, &_vboid); float vertexdata[numfaces*3*3]; // numfaces * 3 vertices per face * 3 dimensions per vertex /* fill */ int = 0; polyhedron::halfedge_const_handle h; (polyhedron::facet_const_iterator faceiter = polyhedron.facets_begin(); faceiter != polyhedron.facets_end(); ++faceiter) { cgal::point_3<kernel> p1,p2,p3; h = faceiter->halfedge(); p1 = h->vertex()->point(); p2 = h->next()->vertex()->point(); p3 = h->prev()->vertex()->point(); vertexdata[i] = p1.hx(); i++; vertexdata[i] = p1.hy(); i++; vertexdata[i] = p1.hz(); i++; vertexdata[i] = p2.hx(); i++; vertexdata[i] = p2.hy(); i++; vertexdata[i] = p2.hz(); i++; vertexdata[i] = p3.hx(); i++; vertexdata[i] = p3.hy(); i++; vertexdata[i] = p3.hz(); i++; } glbindbuffer(gl_array_buffer, _vboid); glbufferdata(gl_array_buffer, sizeof(vertexdata), vertexdata, gl_static_draw); glbindbuffer(gl_array_buffer, 0); // unbind buffer } } void model::drawme() { glbindbuffer(gl_array_buffer, _vboid); /* glerror 1281 generated after line?? */ glenablevertexattribarray(0); glvertexattribpointer(0, 3, gl_float, gl_false, 0, 0);<<std::endl; gldrawarrays(gl_triangles, 0, numfaces*3); /* crashes here */ gldisablevertexattribarray(0); glbindbuffer(gl_array_buffer, 0); }
error message:
exception type: exc_bad_access (sigsegv)
exception codes: kern_invalid_address @ 0x0000000000000008
vm regions near 0x8: --> __text 0000000107ed3000-00000001081a9000 [ 2904k] r-x/rwx sm=cow /users/user/documents/*/project_vvbo.app/contents/macos/project_vvbo
thread 0 crashed:: dispatch queue: com.apple.main-thread
0 glengine 0x00007fff99088f9f glerunvertexsubmitimmediate + 10223
1 glengine 0x00007fff98f558ce gldrawarrays_exec + 626
solved
i didn't realize making copy of "model" object, caused deconstructor called , delete buffer created.
model::~model() { if (_vboid != 0) gldeletebuffers(1, &_vboid); }
many @retokoradi bringing attention
Comments
Post a Comment