#146818 - Rajveer - Sun Dec 09, 2007 6:21 pm
I have a few structs which work fine, and a few which dont. The following works:
Structs:
Allocate:
The following doesn't work:
Allocate:
With the latter, after trying to allocate Track arrays or modify variables such as ret->nTrackModel, nothing happens. If I use malloc instead of calloc, the variables have some (incorrect) values. Also, the last line as well as any call to ret->TrackModelArray or any other array pointers, produces an "error: invalid type argument of '->'" error. Any ideas?
Last edited by Rajveer on Mon Dec 10, 2007 1:17 am; edited 1 time in total
Structs:
Code: |
struct ObjVertex
{ v16 x, y, z; }; struct ObjNormal { v10 x, y, z; }; struct ObjTexCoord { t16 u, v; }; struct ObjTriangle { int Vertex[3]; int Normal[3]; int TexCoord[3]; }; struct ObjTexture { int texture; e.t.c. }; struct ObjModel { int nVertex, nNormal, nTexCoord, nTriangle; int transform[3]; int scale; struct ObjVertex* VertexArray; struct ObjNormal* NormalArray; struct ObjTexCoord* TexCoordArray; struct ObjTriangle* TriangleArray; struct ObjTexture* Texture; }; struct Ship { Stats... struct ObjModel* Model; //Ship's loaded 3D model }; |
Allocate:
Code: |
struct Ship* ret;
// the returned model struct, allocate and clear ret = calloc(1,sizeof(struct Ship)); memset(ret, 0, sizeof(struct Ship)); |
The following doesn't work:
Code: |
struct SplineNode { some variables, pointers }; struct ProgressQuad { some variables }; struct PositionalLight { light stuff }; struct TrackModel { struct ObjModel* Model; s8 type; // 0 = No Collision, 1 = Collision, 2 = Healing Zone }; struct Track { int nTrackModel, nSplineNode, nProgressQuad, nLight; struct ObjModel* LowPolyModel; struct TrackModel* TrackModelArray; struct SplineNode* SplineArray; struct ProgressQuad* ProgressQuadArray; struct PositionalLight* LightArray; }; |
Allocate:
Code: |
struct Track* ret;
// the returned model struct, allocate and clear ret = calloc(1,sizeof(struct Track)); memset(ret, 0, sizeof(struct Track)); . . . ret->TrackModelArray = malloc(sizeof(struct TrackModel)*ret->nTrackModel); ret->TrackModelArray[nM]->Model = ObjLoadModel(file_Location,(int)temp_Variable[0],(int)temp_Variable[1]); //ObjLoadModel works fine, so thats not the problem |
With the latter, after trying to allocate Track arrays or modify variables such as ret->nTrackModel, nothing happens. If I use malloc instead of calloc, the variables have some (incorrect) values. Also, the last line as well as any call to ret->TrackModelArray or any other array pointers, produces an "error: invalid type argument of '->'" error. Any ideas?
Last edited by Rajveer on Mon Dec 10, 2007 1:17 am; edited 1 time in total