B
berthelot samuel
Hi,
I'm trying to develop an application for modeling 3D objects from
Bezier patches, but I have a memory allocation problem. Here are my
structures:
typedef struct _vector3 {
union
{
struct
{
float x, y, z;
};
float v[3];
};
}vector3;
typedef struct _vertex {
vector3 pos;
vector3 normal;
float r, g, b;
}vertex;
typedef struct _tri {
vertex vertices[3];
vector3 normal;
}tri;
typedef struct _patch {
vector3 matrix_cp[4][4]; //16 control points of the patch
vertex patch_vertices[POINTS_ON_CURVE][POINTS_ON_CURVE]; //list of
vertices of the patch
tri* elmt; //list of triangles of the patch
int triCount; //number of triangles on the patch
}patch;
Here is the line I use to allocate the memory for elmt:
g_myPatch->elmt = malloc(((POINTS_ON_CURVE - 1) * (POINTS_ON_CURVE -
1) * 2) * sizeof(tri));
Up to 30 for POINTS_ON_CURVE the program works fine, but beyond this
value, it crashes at the line above. I wonder if it could be related
to the awkward attribute
vertex patch_vertices[POINTS_ON_CURVE][POINTS_ON_CURVE]; of the patch
structure. But I need a 2D array, so I can't avoid it.
Does anybody know where does this problem come from ?
Thx
Sam
I'm trying to develop an application for modeling 3D objects from
Bezier patches, but I have a memory allocation problem. Here are my
structures:
typedef struct _vector3 {
union
{
struct
{
float x, y, z;
};
float v[3];
};
}vector3;
typedef struct _vertex {
vector3 pos;
vector3 normal;
float r, g, b;
}vertex;
typedef struct _tri {
vertex vertices[3];
vector3 normal;
}tri;
typedef struct _patch {
vector3 matrix_cp[4][4]; //16 control points of the patch
vertex patch_vertices[POINTS_ON_CURVE][POINTS_ON_CURVE]; //list of
vertices of the patch
tri* elmt; //list of triangles of the patch
int triCount; //number of triangles on the patch
}patch;
Here is the line I use to allocate the memory for elmt:
g_myPatch->elmt = malloc(((POINTS_ON_CURVE - 1) * (POINTS_ON_CURVE -
1) * 2) * sizeof(tri));
Up to 30 for POINTS_ON_CURVE the program works fine, but beyond this
value, it crashes at the line above. I wonder if it could be related
to the awkward attribute
vertex patch_vertices[POINTS_ON_CURVE][POINTS_ON_CURVE]; of the patch
structure. But I need a 2D array, so I can't avoid it.
Does anybody know where does this problem come from ?
Thx
Sam