I've got a little bug that is blowing my mind. Perhaps it is simple, but I'm totally lost.
I have a basic POD struct
:
struct Data{
bool isInvalid=false;
vec3 *vector; //vec3 is another struct with x,y,z components
Node*node;
bool isFresh;
unsigned int *form;
};
I have a function:
Data getData(){
Data forReturn;
//...populates the forReturn struct
cout<<forReturn.vector->x; //logs correctly a value
return forReturn;
}
The cout
log correctly shows that my return Data
has been populated. But when I call this function from another function, a different story presents:
Data newData=getData(); //logs as above
cout<<newData.vector->x; //is empty!!
What is going on here?! My log output shows these two lines side by side since they occurring right after the other, but what is going on? This is not multithreaded, so variables and pointers should not be changing between these two lines!