diff options
author | KikooDX <kikoodx@paranoici.org> | 2021-12-11 17:49:02 +0100 |
---|---|---|
committer | KikooDX <kikoodx@paranoici.org> | 2021-12-11 17:49:19 +0100 |
commit | b05e8ba7635b70eb2aaadfd681d5adf506805b61 (patch) | |
tree | f90821146fc6117e0db32d8bb1a357d0c8c74c77 | |
parent | cc2e2688d003d940ba7b27225f71dd99e019b9a6 (diff) | |
download | disk-mayhem-main.tar.gz |
fix: particles option set to offmain
Simple fix to the following bug reported by ~demodulatingswan:
> With the particles option set to off, all particles are created and
> added to the entities table, and then erased from the entities table
> by their own update method. When that happens, the draw method is
> never called. But sometimes, the draw method of a particle is called
> before the update method. Because the animation attribute is nil when
> the particles option is set to off, the attempt to call a function
> from this attribute fails and crashes the game. This fix changes the
> draw method to do nothing when the particles option is set to off.
> [...]
Instead of skipping a draw like in their patch, I chosed to destroy the
particle on creation if `particles` is disabled.
-rw-r--r-- | src/particle.lua | 1 | ||||
-rw-r--r-- | src/walk_particle.lua | 1 |
2 files changed, 2 insertions, 0 deletions
diff --git a/src/particle.lua b/src/particle.lua index d3543d4..087f02c 100644 --- a/src/particle.lua +++ b/src/particle.lua @@ -12,6 +12,7 @@ local g = anim8.newGrid(16, 16, Particle.image:getWidth(), function Particle:new(x, y, dx, dy) if not particles then + self:destroy() return nil end self.x = x or 0 diff --git a/src/walk_particle.lua b/src/walk_particle.lua index edb81d4..b7e927f 100644 --- a/src/walk_particle.lua +++ b/src/walk_particle.lua @@ -12,6 +12,7 @@ local g = anim8.newGrid(8, 8, Particle.image:getWidth(), function Particle:new(x, y, dx) if not particles then + self:destroy() return nil end self.x = x or 0 |