Hello,
i searched trough the forums to find the right spot for this topic but i couldnt find something that sounds ok, so i put it here![:)](https://www.mcshaffry.com/GameCode/wcf/images/smilies/smile.png)
As i am still working on particle emitters i just ran into the next problem: When an emitter spawns a particle it generates a PARTICLE_SPAWNED event. An other part of the game listenes to this messages and creates a billboard that is positioned at the position of the particle and follows it. When the particle reaches the end of its lifetime it produces an event PARTICLE_DELETED and is deleted afterwards. Upon receiving the event the game removes the billboard object. The PARTICLE_SPAWNED event carries a pointer to the particle and the PARTICLE_DELETED event carries a pointer to the billboard object.
It can happen that a particle gets generated and the PARTICLE_SPAWNED event is send but not processed before the lifetime of the particle has ended and the particle gets deleted. When the event gets processed it tries to access the pointer to the particle which no longer exists and everything crashes.
This normaly is very unlikely to happen but it can happen (its easy to reproduce with a slow computer
).
So i am now looking for an elegant way to solve this. The quick way is to not enqueue the PARTICLE_CREATED event but to immediately process it. I was thinking about keeping a second list of particles and only if a billboard was created for the particles they are transferred to the real list and only thos on the real list can be deleted. But i would prefer not to have two lists... Another solution would be to remove the PARTICLE_CREATED event if a particle is deleted and it has not yet been processed but i dont have a way to find that specific (only the one for the specific particle) event...
Oh the pointer to the particles are plain dumb standard pointers... Maybe i should try to cenvert the whole physic system to smart pointers...
Ideas on how to solve this?
i searched trough the forums to find the right spot for this topic but i couldnt find something that sounds ok, so i put it here
![:)](https://www.mcshaffry.com/GameCode/wcf/images/smilies/smile.png)
As i am still working on particle emitters i just ran into the next problem: When an emitter spawns a particle it generates a PARTICLE_SPAWNED event. An other part of the game listenes to this messages and creates a billboard that is positioned at the position of the particle and follows it. When the particle reaches the end of its lifetime it produces an event PARTICLE_DELETED and is deleted afterwards. Upon receiving the event the game removes the billboard object. The PARTICLE_SPAWNED event carries a pointer to the particle and the PARTICLE_DELETED event carries a pointer to the billboard object.
It can happen that a particle gets generated and the PARTICLE_SPAWNED event is send but not processed before the lifetime of the particle has ended and the particle gets deleted. When the event gets processed it tries to access the pointer to the particle which no longer exists and everything crashes.
This normaly is very unlikely to happen but it can happen (its easy to reproduce with a slow computer
![;)](https://www.mcshaffry.com/GameCode/wcf/images/smilies/wink.png)
So i am now looking for an elegant way to solve this. The quick way is to not enqueue the PARTICLE_CREATED event but to immediately process it. I was thinking about keeping a second list of particles and only if a billboard was created for the particles they are transferred to the real list and only thos on the real list can be deleted. But i would prefer not to have two lists... Another solution would be to remove the PARTICLE_CREATED event if a particle is deleted and it has not yet been processed but i dont have a way to find that specific (only the one for the specific particle) event...
Oh the pointer to the particles are plain dumb standard pointers... Maybe i should try to cenvert the whole physic system to smart pointers...
Ideas on how to solve this?