Glitch when rendering lots of soft body particles

D

dgreenheck

Guest
I started playing around with the soft body particle system trying to create fluids and came across an odd rendering glitch. Here's a screenshot of the glitch: https://imgur.com/a/Ie0Ne1l

It looks like the vertex buffer is getting overrun. Is there a limit to the number of particles allowed? I've noticed that the glitch appears when I create a single 150x50 box of particles, which isn't a huge number of particles.

I have a particle manager object and a static floor object for the particles to interact with. Here is the code for the particle manager

Create
Code:
physics_particle_set_radius(3);
physics_particle_set_damping(1);
Draw
Code:
var flags = phy_particle_flag_water | phy_particle_flag_viscous | phy_particle_flag_tensile;
physics_particle_draw(flags, 2, spr_water, 0);
Global Left Pressed
Code:
var flags = phy_particle_flag_water | phy_particle_flag_viscous | phy_particle_flag_tensile;
physics_particle_group_begin(flags, 0, mouse_x, mouse_y, 0, 0, 0, 0, c_teal, 1, 1, 2);
physics_particle_group_box(150,50);
mLastGroup = physics_particle_group_end();
 

Mool

Member
HAHAHA. I reported this bug Q1 2019. Still not fixed, BUT I found a workaround

physics_particle_draw_ext(global.liqFlag | phy_particle_flag_elastic, 0, spr_misc_water, 0, 1, 1, 0, global.watercolor, 1)

The only problem with the _ext function is, that your game will crash. Its bugged too. The vertex buffer gets copied into a new one when the water gets more(>4.4k), BUT the old vertex buffer dosnt get freed -> out of memory ->crash!
The workaround for the workaround is:

You need to create WATER_MAX particles at startup so the vertex buffer gets initialized only once. After that everything works well.

If you want to see it in action -> download my app: https://play.google.com/store/apps/details?id=com.gaming_apps.water_physics_simulation

There is also a 3. bug with water particles: The 1.st few water particles dont get drawn correctly at android. :(
 
WATER_MAX particles? I'm interested in this as I started to use soft bodied particles. I noticed the rendering bug when the particle number increased, but I'm not sure what you mean by WATER_MAX particles at startup. Can you give me an example of what that might look like in code?
 

Nidoking

Member
Presumably, just create the maximum number of particles you'll ever need, so that the memory for them is only allocated once. Then there's nothing to leak.
 
Presumably, just create the maximum number of particles you'll ever need, so that the memory for them is only allocated once. Then there's nothing to leak.
Though if I create the maximum number of particles I'll ever need right at the start, I'd essentially be flooding my room, unless I created them in a box offscreen or something, but even still, repositioning the particles would require deleting them, then creating them again at a new x and y, so I think that would ruin the workaround.
 
@Nidoking As he said. I do exactly this. I have a room called room_workaround and there i create all particles so the buffer gets only allocated once.
start room
create all particles
wait 1/2sec (important, idk why, but u need to wait)
delete all particles
goto main room -> play
GG

here is my bug report: https://bugs.yoyogames.com/view.php?id=30375
This is what I'll do. You are quite clever for figuring this out, and I really appreciate you sharing it with me.
 

Mool

Member
I had to find this workaround-workaround, because i have a lot of users and i could not update my app. Thx
 
Top