Jump to content
  • Advertisement
Sign in to follow this  
xwskx

OpenGL glDrawElements problems

This topic is 3905 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm currently using the "glDrawElements" for my program and for some odd reason it blows up frequently with a read access error. I am currently using visual studio and everytime the error occurs, and i look at the stack trace its a memory address. When i check the data in the indexes and vertex pointer all of them are correct. What could be causing this? The glGetError returns 0. I'm totally lost; is there any opengl debugger available for visual studio? Any advice or insight will be greatly appreciated TIA.

Share this post


Link to post
Share on other sites
Advertisement
There is this one that's free
http://glintercept.nutty.org/

There is also gDebugger which is works differently and includes more things like performance analysis.

There are still others

Share this post


Link to post
Share on other sites
Well here is the code, and its pretty simple.


void DrawQuads(struct DtedHeader *dted, int LOD)
{
int x,y;
int limit = dted->NumOfLatitude*dted->NumOfLongitude;
GLushort indices[121*2];
GLuint length;

glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(struct utmCoord),dted->DtedData);
glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(struct RGBstruct),dted->ColorData);

for(y=0;y<dted->NumOfLongitude-1; y+=LOD)
{
length = 0;
for(x=0; x<limit; x+=dted->NumOfLongitude*LOD)
{
indices[length++] = x+y;
indices[length++] = x+y+LOD;
}
glDrawElements(GL_QUAD_STRIP,length,GL_UNSIGNED_SHORT,indices);
}

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
}

Share this post


Link to post
Share on other sites
When i run the debug and see the dissembly the error seems to occur right after the "call dword ptr [__imp__glDrawElements@16 "
and the "cmp esi,esp" is what what is causing the trouble.
The address in the esi, is an invalid memory location. I got this far, but i don't know where to take it from here any ideas?


951: glDrawElements(GL_QUAD_STRIP,length,GL_UNSIGNED_SHORT,indices);
0046F8DE 8B F4 mov esi,esp
0046F8E0 8D 85 F4 FD FF FF lea eax,[indices]
0046F8E6 50 push eax
0046F8E7 68 03 14 00 00 push 1403h
0046F8EC 8B 8D E8 FD FF FF mov ecx,dword ptr [length]
0046F8F2 51 push ecx
0046F8F3 6A 08 push 8
0046F8F5 FF 15 D0 AF B8 00 call dword ptr [__imp__glDrawElements@16 (0B8AFD0h)]
0046F8FB 3B F4 cmp esi,esp
0046F8FD E8 2E 33 FF FF call @ILT+3115(__RTC_CheckEsp) (462C30h)

Share this post


Link to post
Share on other sites
90% of the time the error is caused cause u have left some state on
eg set glDisableClientState( GL_TEXTURE_COORD ) for each texture unit, GL_NORMALs SECONDARDY_COLOR, GL_VERTEX etc

u wont see anything onscreen (but it shouldnt crash) then reenable them one at a time, so u trace which one is causing the problem

Share this post


Link to post
Share on other sites
thanks zedz!

you were totally right i left the GL_TEXTURE_COORD_ARRAY on the previous function. it had multiple exit points and left without disabling it. i guess i learned the hard way why multiple exit points are bad.

thanks for the tip, i've been working on this problem forever. i think i'm going to go back and review my codes to prevent similar mistakes.

Share this post


Link to post
Share on other sites
i wouldnt disable stuff afterward
what ild do is something similar to what i have

all drawing is handled by one function


if ( per_vertex_contains_what & VERTEXATTRIB_VERTEX )
g_rm.ogl.setVertexArrayOFFSET( vertAttribs[0].attrib_size, vertAttribs[0].attrib_format, 0, vertAttribs[0].attrib_offset );
else
g_rm.ogl.DisableVertexArray();

if ( per_vertex_contains_what & VERTEXATTRIB_NORMAL )
g_rm.ogl.setNormalArrayOFFSET( vertAttribs[2].attrib_format, 0, vertAttribs[2].attrib_offset );
else
g_rm.ogl.DisableNormalArray();

if ( per_vertex_contains_what & VERTEXATTRIB_COLOR )
g_rm.ogl.setColorArrayOFFSET( vertAttribs[3].attrib_size, vertAttribs[3].attrib_format, 0, vertAttribs[3].attrib_offset );
else
g_rm.ogl.DisableColorArray();

if ( per_vertex_contains_what & VERTEXATTRIB_TEXCOORD0 )
g_rm.ogl.setTexCoordArrayOFFSET( 0, vertAttribs[8].attrib_size, vertAttribs[8].attrib_format, 0, vertAttribs[8].attrib_offset );
else
g_rm.ogl.DisableTexCoordArray( 0 );

if ( per_vertex_contains_what & VERTEXATTRIB_TEXCOORD1 )
g_rm.ogl.setTexCoordArrayOFFSET( 1, vertAttribs[9].attrib_size, vertAttribs[9].attrib_format, 0, vertAttribs[9].attrib_offset );
else
g_rm.ogl.DisableTexCoordArray( 1 );

etc


ie it will set all states automatically + optimally

Share this post


Link to post
Share on other sites
This is my current way:

if (vertexFormat== VNT)
{
}
else if (vertexFormat== VNTT)
{
}
else if (vertexFormat== VTC)
{
}
else...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!