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 ).
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)
(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!
(PS: here is the crash report, just in case…)
_crash.txt (50.0 KB)