c++ - nvoglv32.dll Access violation reading location 0x00000000 -
i've been having problem lately opengl. in program has worked fine before, try draw group of polygons screen program throws error , life of me can't find cause of it. i've literally changed nothing code, started throwing errors 1 day after coming after month. error is:
unhandled exception @ 0x69f2883e (nvoglv32.dll) in opengltest.exe: 0xc0000005: access violation reading location 0x00000000.
i have reproduced error code below. more strange behavior i've noticed if change call gldrawarrays like:
gldrawarrays(gl_triangles, 3, numv);
or
gldrawarrays(gl_triangles, 0, 258);
then program doesn't throw error though doesn't render properly, rendering half of rectangle, or rendering rectangle plus garbage input.
it's strange, if renders more 255 points works fine less , throws error.
#include <sdl.h> #include <gl/glew.h> #include <math.h> #include <vector> struct vector2f{ public: float x, y; vector2f() {} vector2f(float _x, float _y) { x = _x; y = _y; } }; struct vector3f { public: float x, y, z; vector3f() { x = 0.0, y = 0.0, z = 0.0; } vector3f(float _x, float _y, float _z) { x = _x; y = _y; z = _z; } }; struct vertex { vector3f m_pos; vector2f m_tex; vector3f m_normal; vertex() {} vertex(vector3f pos, vector2f tex) { m_pos = pos; m_tex = tex; m_normal = vector3f(0.0f, 0.0f, 0.0f); } vertex(vector3f pos, vector2f tex, vector3f norm) { m_pos = pos; m_tex = tex; m_normal = norm; } }; sdl_window* window_display = null; sdl_glcontext glcontext; gluint vbo; int width = 800; int height = 600; float ratio = (float)width / (float)height; int numv; std::vector<vertex> _vbo; bool initwindow() { //draw square _vbo.push_back(vertex(vector3f(-0.8f, -0.8f, 0.0f), vector2f(0.0f, 0.0f), vector3f(0.0f, 0.0f, 0.0f))); _vbo.push_back(vertex(vector3f(0.8f, -0.8f, 0.0f), vector2f(0.0f, 0.0f), vector3f(0.0f, 0.0f, 0.0f))); _vbo.push_back(vertex(vector3f(0.8f, 0.8f, 0.0f), vector2f(0.0f, 0.0f), vector3f(0.0f, 0.0f, 0.0f))); _vbo.push_back(vertex(vector3f(-0.8f, -0.8f, 0.0f), vector2f(0.0f, 0.0f), vector3f(0.0f, 0.0f, 0.0f))); _vbo.push_back(vertex(vector3f(-0.8f, 0.8f, 0.0f), vector2f(0.0f, 0.0f), vector3f(0.0f, 0.0f, 0.0f))); _vbo.push_back(vertex(vector3f(0.8f, 0.8f, 0.0f), vector2f(0.0f, 0.0f), vector3f(0.0f, 0.0f, 0.0f))); numv = 6; if (sdl_init(sdl_init_video) < 0) return false; if ((window_display = sdl_createwindow("opengl drawing test", sdl_windowpos_undefined, sdl_windowpos_undefined, width, height, sdl_window_opengl)) == null) return false; glcontext = sdl_gl_createcontext(window_display); glewinit(); return true; } bool drawscene() { glenableclientstate(gl_vertex_array); glclear(gl_color_buffer_bit | gl_depth_buffer_bit); glmatrixmode(gl_modelview); //switch drawing perspective glloadidentity(); //reset drawing perspective glenablevertexattribarray(0); glenablevertexattribarray(1); glenablevertexattribarray(2); glgenbuffers(1, &vbo); glbindbuffer(gl_array_buffer, vbo); glbufferdata(gl_array_buffer, numv * sizeof(vertex), &_vbo[0], gl_static_draw); glbindbuffer(gl_array_buffer, vbo); glvertexattribpointer(0, 3, gl_float, gl_false, sizeof(vertex), 0); glvertexattribpointer(1, 2, gl_float, gl_false, sizeof(vertex), (const glvoid*)12); glvertexattribpointer(2, 3, gl_float, gl_false, sizeof(vertex), (const glvoid*)20); gldrawarrays(gl_triangles, 0, numv); //unhandled exception @ 0x69f2883e (nvoglv32.dll) in opengltest.exe: 0xc0000005: access violation reading location 0x00000000. gldisablevertexattribarray(0); gldisablevertexattribarray(1); gldisablevertexattribarray(2); sdl_gl_swapwindow(window_display); //send 3d scene screen gldisableclientstate(gl_vertex_array); return true; } int main(int argc, char* args[]) { if (initwindow()) { while (drawscene()) {} } return 0; }
Comments
Post a Comment