PDA

View Full Version : Tessellation Memory access error.



Tom Thorp
04-28-2008, 10:45 AM
I"m trying to use tesselator to draw my surfaces and am getting a memory access error on the "vertex[i] += weight[2]...." line.

This occurs after about 100+ calls, so I'm a little confused. The malloc call is not failing. In looking at the disassembled code, it looks like it is a problem with vertex_data[2][i].

I've copied the code from the red book example. I'm running on windows XP and Visual Studio 2005sp1.

Any thoughts on where to check?

Tom

---------------------------------------------------------------
void CALLBACK cls_Pathview_DrawCube::combineCallback(GLdouble coords[3],
GLdouble *vertex_data[4],
GLfloat weight[4], GLdouble **dataOut )
{
GLdouble *vertex;
int i;

vertex = (GLdouble *) malloc(6 * sizeof(GLdouble));
vertex[0] = coords[0];
vertex[1] = coords[1];
vertex[2] = coords[2];
for (i = 3; i < 6; i++)
{
vertex[i] = weight[0] * vertex_data[0][i];
vertex[i] += weight[1] * vertex_data[1][i];
<u> vertex[i] += weight[2] * vertex_data[2][i]; </u>
vertex[i] += weight[3] * vertex_data[3][i];
}
*dataOut = vertex;
}
---------------------------------------------------------------

songho
04-28-2008, 01:26 PM
Make sure that "vertex_data" is 2D array and 6 elements for each vertex, for example, (x, y, z, r, g, b).

I concern more on the deallocation of the local array variable, "vertex", in the combine callback function. How and when do you deallocate the memory from outside of this callback function?