Gldrawelements crash

When I call gldrawelements my program crashes.

When I comment out my shader code it works fine. The code is as follows:

vshader = glCreateShader(GL_VERTEX_SHADER);
fshader = glCreateShader(GL_FRAGMENT_SHADER);

glShaderSource(vshader, length,source, NULL);
glShaderSource(fshader, length,source2, NULL);

glCompileShader(vshader);
glCompileShader(fshader);

shaderprog = glCreateProgram();
glAttachShader(shaderprog,vshader);
glAttachShader(shaderprog,fshader);
glLinkProgram(shaderprog);

loc = glGetAttribLocation(shaderprog, "Tangent");
glEnableVertexAttribArray(loc);
glVertexAttribPointer(loc,3,GL_FLOAT,GL_FALSE,0,tangents);

Running a Radeon 9600 Pro, latest catalyst drivers. Anybody know what I’m doing wrong?

Originally posted by adamnation:
loc = glGetAttribLocation(shaderprog, “Tangent”);
glEnableVertexAttribArray(loc);
glVertexAttribPointer(loc,3,GL_FLOAT,GL_FALSE,0,tangents);
it’s non sense. Write instead :

glBindAttribLocationARB(program, 6, "Tangent"); // Use attrib 6 (reserved for tangents - see glTangentPointerEXT).
glLinkProgramARB(program); // Need to link a second time.	
glVertexAttribPointer(6,3,GL_FLOAT,GL_FALSE,0,tangents);

What about what I wrote is non-sense? Exactly how is that not the proper way to send vertex attributes to a shader?

What benefit is derived from using location six for tangents? Its just a vec3 in the shader anyways. Why is glBind AttribLocations being used instead of what I have?

Confused,
AdamNation :confused:

Dont worry. You can ask for the attribute location AFTER the program was linked, instead of assign manually the slot.

A crash at a glDrawxxxx call, is caused usually by a bad initialization of the used arrays. You probably forgot to disable any array that was previoulsly enabled but is not used, or some of the used arrays are smaller than they should be (perhaps because you are setting up a vec3 vector and passing an array of vec2 vectors), or you are using an invalid pointer… There are a lot of possibilites.

Yes, it might something else than the vertex attrib binding.

Try a very simple shader, see what’s happening, or use GLIntercept, this will help to track down othe issues.

Okay, I’m using glBindAttribLocation as well as gldrawarrays now, I’ve also made sure that all the data was where it was supposed to be, so there’s no missing values, or too-short arrays or anything like that.

Still its crashing. Now when I comment all the shader code out, it runs fine.

One interesting note, after:

glEnableVertexAttribArray(loc);
glVertexAttribPointer(loc,3,GL_FLOAT,GL_FALSE,0,tangents);

I have:

void* foo = NULL;
glGetVertexAttribPointerv(loc[9],GL_VERTEX_ATTRIB_ARRAY_POINTER,&foo);

The value returned to foo is NULL, so looks like there’s trouble with glVertexAttribPointer.

Thanks!
AdamNation

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.