[SOLVED] FX particles make my game crash (and this is… weird 🤔)

Hi guys!



edit: if someone else faces this crash => the problem was “fixed” (more a workaround than an actual solution) by removing the emitter_change function (as a parameter in the particlefx.play function):

local function emitter_state_change(self, id, emitter, state)
	if emitter == hash("emitter") and state == particlefx.EMITTER_STATE_POSTSPAWN then
		self.delete_object = true
		--print("[char_effect] order to delete the object!")
	end
end

function init(self)
	particlefx.play("#"..self.identifier, emitter_state_change) -- is causing the game crash
	--particlefx.play("#"..self.identifier) -- is used to avoid the crash (but is commented here)
end


Recently I’ve been working on “spells” (cf the videos), that spawn special effects over the targeted characters when the player uses them. Ex: flames when using a fire-related spell, electricity when using a lightning-related spell (well… nothing revolutionizing :nerd_face: ).

Here is a bit of context, if it can help…
(note: a bit longer than expected, sorry for that)

I have 3 types of “char_effects” I can combine to create unique effects.
1/ Char transformations > color, scale etc. No problem with this one (I suppose), so I won’t mention it further.

2/ Spine animations > No problem until now, but… who knows.

3/ Particles => the one I’ve added recently and seems to make my game crash).

When a spell is used on a character, this character generates 2 objects (via 2 factories in the character object): spine anim and particles. Both are linked to the same script (char_effect, with conditions inside etc).

If the spine anim and/or the particles are set to unnecessary (in game configs), I still create the corresponding object BUT with an empty animation or an empty emitter (called” none” for the particles). Both are immediately destroyed.

I had no problem with the spine anim, but something seems wrong with the particles… even with the smallest amount of particles.

Here is what my “char_particles” game object looks like:

Let’s take the example of the “Lightning Strike” Spell:

  • 1 Spine animation (electricy residue)
  • 1 “empty” particles emitter (called “none”, cf right above)

Case 1 => I disable the “char_particles” game object spawning (via factory)
(so the spine anim object is the only one to be spawned)

Even if I spam the spell, over several waves of enemies (only the last one in the video to keep it short): no crash. Everything seems ok. Without particles there is no crash.


Case 2 => I allow the “char_particles” game object (cf above) to be spawned (via factory)
(so each char spawns 2 game objects when they’re hit by a spell - 1 for the spine anim, 1 for the particles)

And that’s where it all goes wrong. Even when the emitter spawns “almost nothing” (cf right below), the game crashes.


This seems crazy to me because the “none” emitter is supposed to generate ONE particle (with 1-pixel transparent image), so… this is the bare minimum right?

Plus, all the game objects seem to be deleted properly. It’s like there is a residue of something… somewhere…

Of course, it also crashes with emitters other than “none” (ex: flames etc.), but not faster nor more frequently.
(for some reason it even takes less time to crash when actual particles are generated… but it always, always end up crashing)
image (crash crash and crash again)

What am doing I wrong or missing (about how to manage particles etc.)? Is there something I don’t “clean”? (beyond deleting the game object containing the emitters - that are properly destroyed, as seen above)

Thank you for your help! :pray:

(PS: here is the crash report, just in case…)
_crash.txt (50.0 KB)

Hmm, if I set the “particle life time” value (of the “none” emitter) to 0.01 (from 1), it no longer crashes…

image

But not sure it really solves the issue since I can’t apply the same solution to the other emitters :thinking:

Wow… Just changed a bit of code and removed the “[emitter_state_function]” parameter from the particlefx.play function… and it no longer crashes.

This post took me like… 45min. Embarrassing :see_no_evil: but I’ll gladly delete it if the situation is confirmed.

1 Like

I don’t think deleting is a good idea! You want to leave a record in case someone else has a similar issue.

2 Likes

Also, the engine shouldn’t crash in a case like this.
Don’t forget to add a bug report on Github, and provide a repro case, thx!

2 Likes

Done @Mathias_Westerdahl
I shared the project with Britzl, you and @AGulev , let me know if I should share it with someone else.

3 Likes

The crash sounds like this issue: https://github.com/defold/defold/issues/7142
The workaround suggested by @britzl fixed the crash for us

5 Likes