Page 1 of 1

Issues with sprite engine and cleaning up

Posted: Fri Oct 19, 2018 5:33 pm
by TheGouldFish

In my game I've split up the code into states and try to have each state clean up after its self when it ends.
But I've noticed that if I got between two states quite often that I will eventually blow up the Vram, and this seems to be due to sprites.

So I create my sprites using the spr_addsprite inside a sys_disableinterupts and I then clean up inside another set.
I know that I've not missed any as the check the number of active sprites and they have all been cleared.

I've tried cleaning in the order they were created and the reverse order but after a while I will start getting courrpt graphics and compiling in debug I can see it saying there isn't enough vram.

Message : VDP_allocateSprites(12) success: 45 - remaining = 34
Message : VRAM_alloc(115) failed: no enough free VRAM slot (free = 152)

I've also tried to use the SPR_reset, which in some cases seems to slow the issue down but not always.

I'm sure its something stupid that I'm doing, I just have no idea what.

Re: Issues with sprite engine and cleaning up

Posted: Sat Oct 20, 2018 12:46 pm
by Stef
When doing lot of VRAM alloc / release, you end by having fragmented VRAM and that is an issue to allocate a new sprite.
If you use the last version of SGDK from github repository, you may see the new SPR_defragVRAM() method to force VRAM defragmentation operation. You can do it from time to time to ensure your VRAM remains defragmented.
Anohter way of doing if to use SPR_addSpriteSafe(..) or SPR_addSpriteExSafe(..) methods to ass a new sprite instead of classic ones, so if sprite allocation fail, it will do a VRAM defragmentation and retry the allocation.

Re: Issues with sprite engine and cleaning up

Posted: Sat Oct 20, 2018 4:39 pm
by TheGouldFish
I was working with the last release (134) but I'll give latest another go.
Last time I tried there were lots of compile warnings.

Does doing a SPR_reset clear the vram? and if yes when I call it should I wait for DMA to complete or vsync before adding anymore sprites?

Re: Issues with sprite engine and cleaning up

Posted: Sat Oct 20, 2018 11:03 pm
by TheGouldFish
After more invetigation it looks like I was trying to do to much as I was getting,
Message : DMA_queueDma(..) warning: transfer size is above 7500 bytes.

which then memory stomped or did something bad as it resulted in messing up the VRAM alloc,
VRAM_free(1056) --> remaining = 35430
(it should have been 384)

I guess I was trying to send too much sprite data over, not how I could split it over to transfers so I just created a number of backgounds which works around the issue.

Re: Issues with sprite engine and cleaning up

Posted: Tue Oct 23, 2018 5:21 pm
by Stef
Glad you fixed your problem but normally exceeding the DMA capacity per frame shouldn't be a big issue (it' just a warning as you can see), at worst you may get some slowdowns.. but allocating too much sprites is an important issue. Logs (that you're using with the debug version of the lib) can help to investigate the problem, normally you should see the error in sprite / vram allocation when they happen...