FXGL icon indicating copy to clipboard operation
FXGL copied to clipboard

BUG: In the update method of the ParticleSystem, the particle objects are not correctly recycled back to the object pool. Here, the incorrect reference p of Point2D is used for the recycling process.

Open poetryBoy opened this issue 10 months ago • 2 comments

com.almasb.fxgl.particle.ParticleSystem

override fun onUpdate(tpf: Double) {
        emitters.forEach { (emitter, p) ->
            val particlesList = particles[emitter]!!

            particlesList.addAll(emitter.emit(p.x, p.y))

            val iter = particlesList.iterator()
            while (iter.hasNext()) {
                val particle = iter.next()

                if (particle.update(tpf)) {
                    iter.remove()

                    pane.children.remove(particle.view)
                    Pools.free(p)  //# Here, the incorrect objects have been retrieved.
                } else {
                    if (particle.view.parent == null)
                        pane.children.add(particle.view)
                }
            }
        }
    }

poetryBoy avatar May 09 '25 07:05 poetryBoy

Perhaps this class is not used frequently. From what I can see, it is correct in the ParticleComponent.

poetryBoy avatar May 09 '25 07:05 poetryBoy

Well spotted! It should be particle, not p

AlmasB avatar May 10 '25 10:05 AlmasB