"berthelot samuel" <sa**************@voila.fr> wrote in message

news:ca**************************@posting.google.c om...

Hi,

I have a problem with structures that lose their content when I pass

them to a function.

Here are the structures

typedef struct VERTEX

{

int id; /* id of this vertex */

float x, y, z; /* vertex coordinates */

float u, v; /* texture coordinates */

float r, g, b; /* rgb colour of the vertex */

float normal[3]; /* x y z values of the normal */

}vertex;

typedef struct FACE

{

int vertices[3];/* list of vertices corresponding to this face */

CVector normal; /* x y z values of the normal */

}face;

typedef struct OBJECT3D

{

vertex *vertices; /* hold the vertices of the object3D */

face *faces; /* hold the faces of the object3D */

int vcnt; /* number of vertices of the object3D */

int fcnt; /* number of faces of the object3D */

CVector center; /* center of the object - used for bounding box

*/

float width; /* max width of the object -used for bounding box */

void ComputeBB(); /* compute the bounding box of the object */

}object3D;

typedef struct WORLD3D

{

int numObjects; /* number of objects in the world */

vector<object3D> m_objList; /* list of objects in the world */

}world3D;

And there I create my objects and I add them to a vector

object3D myObject;

memset(&myObject, 0, sizeof(object3D));

g_world.numObjects ++;

myObject.vcnt = 8;

myObject.vertices = new vertex[myObject.vcnt];

myObject.vertices = vertices;

What is this? Why do you assign to vertices twice? What is the veritices

variable?

I think you probably meant something like this

myObject.vertices = new vertex[myObject.vcnt];

for (int i = 0; i < myObject.vcnt; ++i)

myObject.vertices[i] = vertices[i];

myObject.fcnt = 10;

myObject.faces = new face[myObject.fcnt];

myObject.faces = faces;

Some problem again.

g_world.m_objList.push_back(myObject);

You've already used vectors elsewhere in your code, so why didn't you use

them for vertices and faces? As you've seen using pointers and dynamic

memory is tricky. Consider doing this instead

struct OBJECT3D

{

vector<vertex> vertices; /* hold the vertices of the object3D */

vector<face> faces; /* hold the faces of the object3D */

CVector center; /* center of the object - used for bounding box */

float width; /* max width of the object -used for bounding box */

void ComputeBB(); /* compute the bounding box of the object */

};

john