Issues with ParticleIterator in Mogre
I've been trying to translate the Demo_Water example to C#. The translation itself is done, but I've been facing an issue with the ParticleIterator wrapper class. Namely, I have a particle system whose NumParticles property is 100, and the following ParticleIterator code:
ParticleIterator pit = particleSystem._getIterator();
Particle particle = pit.Next;
This code crashes my application right at
pit.End() with an unhandled exception. Nothing shows up on Ogre.log.
Has anyone had problems with ParticleIterator before?
I've just had the same problem.
Fortunately, we know the quota used to create the particle system, and I just found this wee beauty:
Particle ParticleSystem.GetParticle(uint index)
Try this and see how you get on:
for (int i = 0; i < particleSystem.ParticleQuota; i++)
// do what you want to the particle e.g. set all to uniform velocity:
(particleSystem.GetParticle((uint)i)).direction = myVelocity;
btw, if that works, could you post your demo, as I'd love to have that code!
As an afterthought, note that after you have created your particle system object, and set its quota, and attached the particle system to its scene node (i.e. attached it to the scene graph that Ogre will render), ONLY THEN (it would seem) will the actual particles be created, so only after that will you be able to access the particles individually.
Hope that helps.
NOPE! Sorry, that won't work either. The GetParticle() method doesn't seem to want to let me write to the particle.
So, sorry, that's been of no help I'm afraid.
It seems that large parts of the ParticleSystem API of Ogre are broken in Mogre. Nearly every method that involves manipulating particles manually is broken.
The CreateParticle() method always returns null, attempting to access particles by index results in a crash, iterator calls also crash. What can be so fundamentally wrong with the wrapper that resulted in this odd behaviour? Has anyone ever got to do anything with dynamic particles in Mogre, besides using the scripts?
Have a look at this link:
Especially the following quotes:
while in my program, it fails at the method "createParticle" itself, i create a particle right after the creation of the ParticleSystem instance. and it attempts to fetch a particle from a free particle list, but the list is empty at that time, which caused the crash.
Ha right, I think I encountered this problem as well. You'll have to work around it, I think you can only start creating particles after you have rendered at least one frame since creating the particle system.
It would seem that the Mogre particle system code/behaviour is correct, but that one frame needs to be rendered between creation of the particle system object, and the manual creation of particles themselves.
I haven't tried it myself yet, so good luck!
Yup, that's right. I had found out about it a couple of weeks back, but forgot to post it up in the forum.
It certainly appears that Ogre's particle creation behaves like that. If i wait for one frame to be rendered, everything works as it should. Which isn't to say this is completely ok... It's certainly an obscure way to do it.
Thanks for that.
I think the design may be based on the need to wait for the render system to be set up (hardware rendering of particles?)
Anyways, I think we can call this one closed, for now!