Bug in CParticlePointEmitter

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
runelord
Posts: 13
Joined: Sat Jan 21, 2006 10:37 am

Bug in CParticlePointEmitter

Post by runelord »

@latest SVN

Reproduce:
change in the specialFX example the box emitter to a point emitter. you are lucky if you see any particle at all, even with a very small direction vector.

Possible reason:
Particle.pos was never initalized + it's passed by reference and thus adds up the starting position pretty fast.

fix:
reset the position to 0,0,0
e.g:
add the line
Particle.pos = core::vector3df(0.f, 0.f, 0.f);
inside the emit() method. :)
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, that can't be the fix. The pos is initialized by the vector constructor to (0,0,0) and is never changed, so it will be the same all the time.
runelord
Posts: 13
Joined: Sat Jan 21, 2006 10:37 am

Post by runelord »

I'm sure you didn't look up the code. It works pretty well.

1. Point Emitter:
The Particle structure is created just once and that is upon the creation of the emitter class.

2. ParticleSystemNode:
now the CParticleSystemNode calls the emitt() method:

Code: Select all

s32 newParticles = Emitter->emitt(now, timediff, array);
3. Point Emitter:
inside the emitt() method the particle structure is passed back as a reference to the doParticleSystem() method of the CParticleSystemNode.

Code: Select all

outArray = &Particle;
4. ParticleSystemNode:
later in the doParticleSystem() method the array.pos vector is being altered,

Code: Select all

if (ParticlesAreGlobal)
 AbsoluteTransformation.transformVect(array[i].pos);
which is identical to the Point Emitter Particle member.


unless i'm a totally idiot and incapable of reading clean written code i claim that not resetting the particle.pos to (0,0,0) is a bug, and resetting it for each particle is one of the possible fixes. =P
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Ok, in fact I did check the code, but assumed a better copy handling in the ParticleSystemSceneNode. I have now fixed the copying there, i.e. the ParticleData is copied first and the transformation is applied to the copied value. I guess it would be best to change the parameter to ref-pointer-const as well.
So in short: You were right, but I think my solution is safer for general Emitter implementations.
runelord
Posts: 13
Joined: Sat Jan 21, 2006 10:37 am

Post by runelord »

aye your right. A class should never pass back a non const pointer of a private member. Only the owner should be allowed to modify its data.
Post Reply