问题
In my program (it is for a homework assignment), I load in a model which is a bunch of vertices and normals etc into a struct I have. When drawing it, I pass the model to a function void drawModel(Model model). Doing that gives me this error:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
I was looking around, and one answer seemed to be that it was because what I'm passing is too large and it's messing up the compiler. So I tried changing it so the drawModel function accepts a pointer to the struct (which I should've done to begin with...), but as soon as I access it in the function I get that error.
How can I get around this? And why is this happening?
Here's the entire function
void drawModel(Model * model)
{
int i, g; //i is the main iterator, g keeps track of what part we're on
int edge; //The current edge we're on
g = 0;
for(i = 0; i < (model->faceCount); i++) //This is just to test why it's occuring
{
}
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, model->vertices);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(3, GL_FLOAT, 0, model->normals);
for(i = 0; i < (model->faceCount); i++) //Right here is where i get the error
{
if(i == model->parts[g])
{
//Set colour to the part colour
g++;
}
glDrawElements(GL_POLYGON, model->faces[i].edges, GL_UNSIGNED_BYTE,
model->faces[i].edge);
}
}
Note: I've never used GL vertex arrays before, this is my first attempt.
I was calling drawModel like so: drawModel(&plane);
回答1:
The problem was
glNormalPointer(3, GL_FLOAT, 0, model->normals);
It should've read
glNormalPointer(GL_FLOAT, 0, model->normals);
来源:https://stackoverflow.com/questions/5520441/run-time-check-failure-0-why-am-i-getting-this-and-what-does-it-mean