Problems after pushing back into the vector

Hi,

I'm trying to simulate a particle generator with c++ and opengl. I have a class for emitter and a class for particle. I have a code here where I want to create some particles JUST from the emitter constructor:

1
2
3
4
5
6
7
8
9
10
11
  Emitter::Emitter(GLuint nrParticles, glm::vec3 position, GLfloat radius, GLchar *imgName)
{
	this->m_Position = position;
	this->m_radius = radius;

	for (int i = 0; i < nrParticles; i++)
	{
		this->particles.emplace_back(Particle(glm::vec3(0.0f), glm::vec3(0.0f), 0.0f, imgName));
	}
 
}


Well, the Particle constructor binds some buffers with some ID's: 1, 1 and 2. But after I emplace back into the vector and it returns to main function (where the emitter constructor was called) the buffers have the same ID, something like 341232415. And the particles are not drawn. If I create a single particle from Particle constructor in main function it's drawing.
Also something weird. Yesterday I don't know how, but with the code above(creating some particles from emitter) and creating a single particle from the Particle constructor, both in main, it drew both, the particles from emitter and the one from Particle instantiated.
I'm so frustrated because for 2 days I try to figure this. :D
Is there somebody who has some ideea about my problem? Is something with copy constructor ? If you need all the code I have uploaded on github.
https://github.com/noblind119/CppGLrepository

Thanks in advance.
But after I emplace back into the vector and it returns to main function (where the emitter constructor was called) the buffers have the same ID, something like 341232415.

That number looks suspiciously like an uninitialized variable is being used. Are you sure you're properly initializing all of the class variables?

By the way it would probably be better if your github link contained the code instead of the rar file, not everyone will download and extract the rar file.

Hi,

Thank you for your reply.
I found what was the problem. In the code is used a copy constructor(Particle). Somebody told me that the object was created, copied and destroyed during the "push_back" and the copy lives on in the vector, and is destroyed after returning. So that's why my variables didn't keep their values. :P
Also I've removed the zip file on github and uploaded the files. :P
Topic archived. No new replies allowed.