Starting a fade in/out sometimes crashes on hardware

SGDK only sub forum

Moderator: Stef

Post Reply
Grind
Very interested
Posts: 69
Joined: Fri Jun 13, 2014 1:26 pm
Location: US
Contact:

Starting a fade in/out sometimes crashes on hardware

Post by Grind » Sat Nov 05, 2016 3:52 pm

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.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

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

Post by Stef » Sat Nov 05, 2016 5:07 pm

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.

cero
Very interested
Posts: 340
Joined: Mon Nov 30, 2015 1:55 pm

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

Post by cero » Sat Nov 05, 2016 5:42 pm

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?

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

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

Post by Sik » Sat Nov 05, 2016 7:47 pm

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?
Sik is pronounced as "seek", not as "sick".

Grind
Very interested
Posts: 69
Joined: Fri Jun 13, 2014 1:26 pm
Location: US
Contact:

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

Post by Grind » Sat Nov 05, 2016 8:39 pm

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.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

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

Post by Stef » Sat Nov 05, 2016 10:02 pm

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 :)

Grind
Very interested
Posts: 69
Joined: Fri Jun 13, 2014 1:26 pm
Location: US
Contact:

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

Post by Grind » Sun Nov 06, 2016 12:01 am

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.

Mask of Destiny
Very interested
Posts: 624
Joined: Thu Nov 30, 2006 6:30 am

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

Post by Mask of Destiny » Sun Nov 06, 2016 4:17 am

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.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

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

Post by Stef » Sun Nov 06, 2016 10:03 pm

Oh you're right, I completely forget to protect the read palette method (writes are ok) :)
I will commit change asap !

Edit: Commited !

cero
Very interested
Posts: 340
Joined: Mon Nov 30, 2015 1:55 pm

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

Post by cero » Mon Nov 07, 2016 11:15 am

Thanks.

Post Reply