Page 1 of 1

Starting a fade in/out sometimes crashes on hardware

Posted: Sat Nov 05, 2016 3:52 pm
by Grind
I had an issue in my project for a while where the game would hang between room transitions (fading). It would only happen on hardware, not emulators (except BlastEm) which reported

Code: Select all

Read from VDP data port while writes are configured, CPU is now frozen. VDP Address: 2, CD: 5
Mask of Destiny wrote: it looks like the problem is that sometimes a vertical interrupt occurs during a call to VDP_getPaletteColors (which is in turn called by VDP_fadeTo). VDP_getPaletteColors should probably disable interrupts write before setting up reads on the VDP and then turn them back on after it's done reading the current palette. That said, you can probably fix this by doing a VDP_waitVSync before calling VDP_fadeTo.
I've only seen it happen before on async fade so I just disable interrupts before calling, but that wouldn't make sense for a blocking one. Calling VDP_waitVSync first is rather wonky.

Re: Starting a fade in/out sometimes crashes on hardware

Posted: Sat Nov 05, 2016 5:07 pm
by Stef
Indeed there is many luck that interrupt occurs during the fading process. Normally later SGDK protect the method against that, but not all methods are protected because it would generate many CPU overhead so it's better to let user/developer to deal with that in a more efficient way.

Re: Starting a fade in/out sometimes crashes on hardware

Posted: Sat Nov 05, 2016 5:42 pm
by cero
I think I've seen this a few times too. But I use sync fading only.

edit: Perhaps the call should be protected if async is false?

Re: Starting a fade in/out sometimes crashes on hardware

Posted: Sat Nov 05, 2016 7:47 pm
by Sik
Stef wrote:Indeed there is many luck that interrupt occurs during the fading process. Normally later SGDK protect the method against that, but not all methods are protected because it would generate many CPU overhead so it's better to let user/developer to deal with that in a more efficient way.
Yeah, I assume it's safe for all blocking ones though, that's the least performance critical stuff by definition after all =P

I'm guessing this case was an oversight anyway?

Re: Starting a fade in/out sometimes crashes on hardware

Posted: Sat Nov 05, 2016 8:39 pm
by Grind
I tried putting this into my title screen loop, and it doesn't seem to freeze the game at all (ate controller inputs though).

Code: Select all

SYS_disableInts();
VDP_waitVSync();
VDP_waitVSync seems to re-enable interrupts (or at least just VInt), so maybe it would be just fine to leave it the way it is, and call SYS_disableInts() even before synchronous fades. Guess the answer is subjective at this point.

Re: Starting a fade in/out sometimes crashes on hardware

Posted: Sat Nov 05, 2016 10:02 pm
by Stef
waitVSync() doesn't re-enable interrupts so in your case you indefinitely disable interrupts which is a big problem :p
you should always use SYS_enableInts() after a SYS_disableInts() call.

Yeah, I assume it's safe for all blocking ones though, that's the least performance critical stuff by definition after all =P
Blocking fading now correctly handle that on SGDK, even non blocking ones for the last version :)
I added more security here and there (by disabling temporary ints) but of course i tried to do that only on methods that you don't use too much :)

Re: Starting a fade in/out sometimes crashes on hardware

Posted: Sun Nov 06, 2016 12:01 am
by Grind
Oh I see, I misunderstood how VDP_waitVSync works. I thought disabling interrupts might make it loop indefinitely, but the vblank flag it checks seems to be changed regardless.

Re: Starting a fade in/out sometimes crashes on hardware

Posted: Sun Nov 06, 2016 4:17 am
by Mask of Destiny
Stef wrote:Blocking fading now correctly handle that on SGDK, even non blocking ones for the last version :)
Still looks broken on Github to me. VDP_fadeTo calls VDP_getPaletteColors without waiting for VSync or disabling interrupts and VDP_getPaletteColors doesn't do that either.

Re: Starting a fade in/out sometimes crashes on hardware

Posted: Sun Nov 06, 2016 10:03 pm
by Stef
Oh you're right, I completely forget to protect the read palette method (writes are ok) :)
I will commit change asap !

Edit: Commited !

Re: Starting a fade in/out sometimes crashes on hardware

Posted: Mon Nov 07, 2016 11:15 am
by cero
Thanks.