Crash behaviour (and maybe you can give some thoughts on what might be causing it.)

When a game crashes on the Playdate unit, if it is some sort of coding or maths error, would it usually show an error message on the screen, like what you would see on the simulator's console?

Or does it always crash to the screen that shows some building blocks, and just says something like "something went wrong, press A to restart"?

Further details.....

I'm working on a game that involves shooting what is basically a machine gun.
I have an array to contain my bullet sprites, which I cycle through, adding new bullets in the space where an expired bullet was previously stored. This means that I only ever have 8 bullets assigned to the array. When a bullet either reaches the end of it's path, or collides with a wall or enemy, It is :remove()ed, and a new bullet will be assigned to it's place in the array.

When I play the game on my actual Playdate, performance seems fine, but after a while, after going through a few rooms of the game, clearing enemies, I will start getting massive frame-rate drops, and eventually the game crashes.

It seems to me that it would be something to do with building up huge numbers of redundant sprites. but, even if I'm not properly removing the sprites, which I'm fairly sure that I am, the fact that all bullets are assigned to an array that never goes above 8 entries, should mean that the garbage collector should still be tidying up any bullet sprites that are no longer part of the array. right?

I've tried putting print(gfx.sprite.spriteCount()) in my main update loop, and seeing if the number of sprites increases as I transition between game rooms and firing my blaster.
But the number of sprites doesn't seem to increase.

Any ideas on what might be happening, or what steps I might take to try and find the cause?

Thanks.

Plug the device into your computer, open the Simulator, view device info from the Window menu. Check memory/cpu usage.

Post some screenshots if unsure.

It sounds like you're trying to make a kind of particle fx buffer for your bullets, but there are a couple of things you need to bear in mind:-

  1. Do you create a new sprite with every bullet? If you do then assigning the sprite to an already used spot in your buffer won't necessarily clear up the memory used by it's previous entry. If all refs to the old entry are destroyed then sure the memory will be earmarked for destruction, but that's not the same thing as getting the memory immediately back.

  2. Are you only storing bullets in the buffer? If you can get away with it, it's better to re-use existing bullet sprites rather than creating and hopefully destroying bullets once you've gone beyond your 8 bullet cap. Why not create 8 sprites for the bullets before the game starts and just re-use them in the main game loop, never creating or destroying any memory at all? You can just move a bullet offscreen if you want to hide it.

  3. Are you committed to using sprites for the bullets? Simply drawing the bullets using an image:draw every frame would get around any possible issues with sprites chowing down on memory, but you might take a performance hit. Still, better than a memory leak causing a crash :slight_smile: