Not quite sure why this is happening but I have the following code:
vector<glm::vec3>& HeightMap::Vec3Vertices() {
vector<glm::vec3> vecs;
for (unsigned int i = 0; i < vertices.size(); i += 3) {
vecs.push_back(glm::vec3(vertices[i], vertices[i + 1], vertices[i + 2]));
}
return vecs;
}
Now later in my main code I have:
vector<glm::vec3>& vertices = hm.Vec3Vertices();
Where hm
is a Height Map object.
I'm in Release Mode
I use vertices
later and when I do the size is correct but all the data within it is unreadable. When I step through the code it appears as though the compiler has optimized out the initialization of the vecs
in Vec3Vertices()
On the other hand if I change it so that I do not pass by reference
vector<glm::vec3> HeightMap::Vec3Vertices() {
and
vector<glm::vec3> vertices = hm.Vec3Vertices();
It all works perfectly. Any ideas on why this might be? I am aware that passing by value will probably result in the compiler using a move operation anyways, I just can't for the life of me figure out why my pass by reference is invalid in the first place. Thanks in advance