Run time error: function wont create my dynamic array


I need to create an array dynamically after reading obj coordinates from a file. The issue I'm having is that the dynamic array, needed to store my vertex group (normal position and texture coordinates), "forgets"/doesn't record the data after its leaves the function.

Why wont this section be remembered when my function terminates?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
void Create_Array( mesh * make_mesh)
{
vector<mesh> collect_meshdata; 
...
...
int imesh_size;
make_mesh = new mesh[imesh_size]

int i = 0;
for  ( it = collect_meshdata.begin();it < collect_meshdata.end() && i< *pi_3dMesh;   it++, i++)

{

  make_mesh [i].Position.x = it->Position.x;
				 make_mesh [i].Position.y = it->Position.y;
				 make_mesh [i].Position.z = it->Position.z;
				 //copy the texture coordinates
				 make_mesh [i].Texture.x  = it->Texture.x;
				 make_mesh [i].Texture.y  = it->Texture.y;
				 //copy the normal coordinates
				 make_mesh [i].Normals.x  = it->Normals.x;
				 make_mesh [i].Normals.y  = it->Normals.y;
				 make_mesh [i].Normals.z  = it->Normals.z; 

}

}
Last edited on
Hi!

Hint 1: When you're passing make_mesh is it the actual pointer that is passed or is a copy of it created?

Hint 2: Change the argument type to mesh *& make_mesh in the argument list and try again. You should explain to yourself how and why this works, by the way!

/Corpus
That's because you are sending a copy of the pointer. (its value)
You better return the pointer (transfer ownership)...
Wait, ¿why don't just return the vector?
@Corpus thank you 1000 times, 2 weeks error solved
Topic archived. No new replies allowed.