phaser3-weapon-plugin icon indicating copy to clipboard operation
phaser3-weapon-plugin copied to clipboard

Possible memory leak in physics collisions?

Open amaccann opened this issue 5 years ago • 4 comments

Hey, using your plugin and wired together the basic 'on mouse pressed' example that fires some random bullets. IE:

if (this.input.activePointer.isDown) {
  this.weapon.fire();
}

so that works fine. However, if I include the overlap() Arcade Physics logic to track collisions between my other scene sprites & weapon bullets, I notice that the FPS collapses after a while. It goes from a smooth 60fps, to < 10fps. I keep the mouse button down and after about 10 seconds, the FPS starts dropping. Letting go of the mouse, but the FPS continues to drop.

this.physics.add.overlap(this.allSprites, this.weapon.bullets, (actor, bullet) => {
    bullet.kill();
});

So I don't have any particular debug info: the FPS drop for sure happens if the overlap() logic is included (this.allSprites contains a bunch of normal ArcadeSprite sprites).

Without that overlap logic, holding the mouse button down doesn't cause the FPS drop at all. I wonder is there something going on with the Bullets when they 'die' yet they're still being cached by the ArcadePhysics overlap() function?

The plugin is great and just what I need, but this FPS lag means I can't use it ATM. I probably could hot-patch some 'fake' physics overlap logic, but would be a shame not to use the code provided out-of-box.

amaccann avatar Aug 27 '19 16:08 amaccann

Also to clarify, this leak happens regardless if the callback with bullet.kill(); is called or not - and whether the callback is defined or not. So this.physics.add.overlap(this.allSprites, this.weapon.bullets); still causes the FPS drop.

amaccann avatar Aug 27 '19 17:08 amaccann

Thanks for the in-depth report. I’ll see if I manage to reproduce, and let you know what I find out.

16patsle avatar Aug 28 '19 06:08 16patsle

Although it's been a while I though I should let you know that I haven't been able to reproduce the issue. If you still experience it yourself I created an example in examples/physics-overlap.js if you want to try that. Otherwise I guess we can just close the issue.

16patsle avatar Apr 10 '20 16:04 16patsle

@16patsle Fair enough; it has been a while lol but I might take another shot at this and see what might have been happening 👍 If you want to close the issue that's fine - thanks for getting back on this though!

amaccann avatar Apr 15 '20 10:04 amaccann