Particles System with a little memory leak...

View previous topic View next topic Go down

Particles System with a little memory leak...

Post  magictech on Tue Jun 23, 2009 8:29 am

Hi guys, i was implementing the particles system in my game when i found this memory leak, but its easy to correct...

In the sio2_emitter.cc in the sio2EmitterRender method replace:

Code:
++_SIO2emitter->n_particle

to

Code:
if (_SIO2emitter->n_particle < _SIO2emitter->maxp - 1) {
++_SIO2emitter->n_particle
}

and just for precaution replace too in the same method:

Code:
--_SIO2emitter->n_particle

to

Code:
if (_SIO2emitter->n_particle > 0) {
--_SIO2emitter->n_particle
}


If you put the line below in the themplate.mm in the first line of particle_render method on tutorial12, you will see what iam saying...

Code:
printf("%d\n", _SIO2emitter->n_particle);

I hope to helped someone...

magictech

Posts : 13
Join date : 2009-01-23

View user profile http://www.magictech.com.br

Back to top Go down

Re: Particles System with a little memory leak...

Post  sio2interactive on Tue Jun 23, 2009 5:01 pm

Hummmm I don't know but I test in tutorial12 with the original code again with MallocGuard and Instruments Leaks and there's no leak whatsoever...

Can you please double check?

Tks!

_________________
SIO2 Interactive
Free Open Source 3D Game Engine for iPhone and iPod Touch
http://sio2interactive.com
avatar
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 37
Location : Shanghai

View user profile http://sio2interactive.com

Back to top Go down

Re: Particles System with a little memory leak...

Post  magictech on Tue Jun 23, 2009 7:43 pm

Did you inserted the line that i sugested in tutorial12 render method to print the number of particles? You will see for example that fire has a maxp = 60, but after some renders (about 200) the number of particles keep increasing... and how the number of particles can be greater than maxp? Maybe i'am crazy, but im my game without the changes that i sugested, the particles stop to render in about 5 seconds... Wink

magictech

Posts : 13
Join date : 2009-01-23

View user profile http://www.magictech.com.br

Back to top Go down

Re: Particles System with a little memory leak...

Post  sio2interactive on Tue Jun 23, 2009 8:31 pm

Hummmm not sure what is wrong with your implementation but for me no element of the _SIO2emitter->_SIO2particle is accessed with a value higher than the maxp... You have to take note that _SIO2emitter->n_particle, is the current particle number and because of the n_particle = ( unsigned int )( _SIO2emitter->sync_time / _SIO2emitter->pps ); approximation it might go up a bit or down a bit compare to maxp which is 100% normal... _SIO2emitter->n_particle is an approximation of the current number of activated particles and in no way this will create leaks or access an element array that have not been initialized...

Add this line to verify it:


if( j >= _SIO2emitter->maxp )
{
printf("%d:%d\n", j, _SIO2emitter->n_particle);
}

_________________
SIO2 Interactive
Free Open Source 3D Game Engine for iPhone and iPod Touch
http://sio2interactive.com
avatar
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 37
Location : Shanghai

View user profile http://sio2interactive.com

Back to top Go down

Re: Particles System with a little memory leak...

Post  magictech on Tue Jun 23, 2009 10:40 pm

Really... i saw that... but why it's crashing i don't know yet... Smile

magictech

Posts : 13
Join date : 2009-01-23

View user profile http://www.magictech.com.br

Back to top Go down

Re: Particles System with a little memory leak...

Post  magictech on Tue Jun 23, 2009 10:58 pm

I've discovered... it's why i was using ((SIO2emitter*)_ptr)->n_particle on render method for performance meter and it's have a number greater than ((SIO2emitter*)_ptr)->maxp after some time without my changes on sio2EmitterRender Wink now... i don't know if it's correct or not... you tell me...

magictech

Posts : 13
Join date : 2009-01-23

View user profile http://www.magictech.com.br

Back to top Go down

Re: Particles System with a little memory leak...

Post  sio2interactive on Wed Jun 24, 2009 7:40 am

It is correct... You must have a leak somewhere else use mallocguard and leaks...

_________________
SIO2 Interactive
Free Open Source 3D Game Engine for iPhone and iPod Touch
http://sio2interactive.com
avatar
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 37
Location : Shanghai

View user profile http://sio2interactive.com

Back to top Go down

Re: Particles System with a little memory leak...

Post  Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum