Page 1 of 3

Particle System bugs

Posted: Tue May 11, 2010 3:07 pm
by mv2112
As the title suggests, i'm doing a little side project. I'm making a particle system with SDL. Right now it works, there are just a few bugs and anomalies. First of all, i have a particle class and a particle handler class. Each particle handler class has an array of 10000 particles. The particle handler can start, stop, set, and render particles.

My first problem is this:

Code: Select all

Unhandled exception at 0x004133d7 in project.exe: 0xC00000FD: Stack overflow.
This is the error i get when i have more than about 10000 particles in my particle handler, and when i have more than 2 particle handlers running.

Is there any way around this?
Also, the speed of the particles depends on how many there are, 2 particles move faster than 10000. How can i fix this?

I'll post the code if you need it, just ask.

Re: Particle System bugs and stack overflow

Posted: Tue May 11, 2010 5:38 pm
by K-Bal
Wait. You are saving the particles as class member of you particle handler? Like Particle myParticles[10000]?

You should use malloc / new / dynamic containers for large memory allocations.

Re: Particle System bugs and stack overflow

Posted: Tue May 11, 2010 5:42 pm
by mv2112
K-Bal wrote:Wait. You are saving the particles as class member of you particle handler? Like Particle myParticles[10000]?

You should use malloc / new / dynamic containers for large memory allocations.
I'll try that..

EDIT:
About how many particles should a particle system hold?

Re: Particle System bugs and stack overflow

Posted: Tue May 11, 2010 6:40 pm
by dandymcgee
As with all particles systems, make sure you are pooling instances. Rather than deleting the object when it dies and creating a new one, simply set a flag and reuse one of the already existing particles that's flagged dead to "spawn" a new one.

Re: Particle System bugs and stack overflow

Posted: Tue May 11, 2010 6:58 pm
by mv2112
dandymcgee wrote:As with all particles systems, make sure you are pooling instances. Rather than deleting the object when it dies and creating a new one, simply set a flag and reuse one of the already existing particles that's flagged dead to "spawn" a new one.
Each particle has a Boolean "alive". If there are less particles alive than there were specifed (if particles have died), it loops through the array of particles and resets them untill the amount of alive particles equals the amount specified. But what should the limit be on how many particles to have? Each of my particle handlers has 10,000 particles. Is this a good amount?

I just found out that it lags less when i turn debugging off lol :mrgreen:

Re: Particle System bugs and stack overflow

Posted: Tue May 11, 2010 8:17 pm
by dandymcgee
mv2112 wrote:But what should the limit be on how many particles to have? Each of my particle handlers has 10,000 particles. Is this a good amount?
Depends on the desired effects, the rest of the environment, and most importantly personal preference. It's completely arbitrary.

Whether or not 10,000 is ideal is up to you, but I'd say that's certainly a good upper limit.

Re: Particle System bugs and stack overflow

Posted: Thu May 13, 2010 6:07 pm
by mv2112
Anyone know how you could calculate a point along a circle? Some sort of formula?

Re: Particle System bugs and stack overflow

Posted: Thu May 13, 2010 6:56 pm
by Ginto8
mv2112 wrote:Anyone know how you could calculate a point along a circle? Some sort of formula?
Well, using the unit circle, a point along it at any angle x is (cos x,sin x), so a point at angle x on a circle with radius r is (r cos x,r sin x). However, this computation is pretty costly so unless you NEED (and I really mean NEED) to use it, you really shouldn't.

Re: Particle System bugs and stack overflow

Posted: Tue May 18, 2010 6:14 pm
by mv2112
Posted a video of my particle system!
http://www.youtube.com/watch?v=_bG-vWB5n9Y
ps. Thanks for subscribing LusikkaMage

Re: Particle System bugs and stack overflow

Posted: Tue May 18, 2010 7:46 pm
by eatcomics
Dude that looks amazing :D you should really implement it into your game

Re: Particle System bugs and stack overflow

Posted: Tue May 18, 2010 10:30 pm
by Ginto8
eatcomics wrote:Dude that looks amazing :D you should really implement it into your game
this. It looks fantastic; great comeback from explicitly calling a destructor. :lol:

Re: Particle System bugs and stack overflow

Posted: Sat May 22, 2010 11:37 pm
by mv2112
I just tried to edit the system to work with openGL. It works but it is very noticeably slower than with plain SDL. I am using openGL with SDL. Is there any reason why its slower?
Here is the render code.

Code: Select all

glColor3f(0,0,255);
glBegin(GL_QUADS)
for(int i=0;i<pamount;i++)
{
   Particle[i]->Render();
}
glEnd()
Render()

Code: Select all

glVertex2f(Rect.x,Rect.y);
glVertex2f(Rect.x+Rect.w,Rect.y);
glVertex2f(Rect.x+Rect.w,Rect.y+Rect.h);
glVertex2f(Rect.x,Rect.y+Rect.h);

Re: Particle System bugs

Posted: Sun May 23, 2010 6:00 am
by K-Bal
You are using immediate mode which is very slow. You should try using vertex buffer objects with index buffers and object batching. Ask GroundUpEngine :lol:

Re: Particle System bugs

Posted: Sun May 23, 2010 6:29 am
by GroundUpEngine
K-Bal wrote:You are using immediate mode which is very slow. You should try using vertex buffer objects with index buffers and object batching. Ask GroundUpEngine :lol:
I would help, but I have no idea how vertex buffer objects work...

Sorry! ;)

Re: Particle System bugs

Posted: Sun May 23, 2010 7:08 am
by K-Bal
I go into more detail. You should save the particle centers as vertices in a VBO. Then render everything with the point sprite extension. However, since you are not using any textures, you could just render the VBO as GL_POINTS.
GroundUpEngine wrote:
K-Bal wrote:You are using immediate mode which is very slow. You should try using vertex buffer objects with index buffers and object batching. Ask GroundUpEngine :lol:
I would help, but I have no idea how vertex buffer objects work...

Sorry! ;)
Are you serious? :lol: You did your terrain with VBOs and you don't know how they work? ;)