jojobear13 / shinpokered

Mostly-vanilla hack of Pokémon Red/Blue focused on bugfixes and trainer ai
209 stars 42 forks source link

Bug: Sprites invisible during Itemfinder sfx loop #265

Closed Mord5 closed 12 months ago

Mord5 commented 1 year ago

What emulator and/or hardware are you are using? bgb 1.5.9.w64

What version of this project are you using? built from source master_dev commit https://github.com/jojobear13/shinpokered/commit/600a3a1b8ddd14cec34e5498090b71a5f503766e

What is the problem you encountered? Overworld sprites are invisible after using the Itemfinder while its sfx loop is playing. Overworld sprites reappear at the same time as the text box.

Is it possible to reproduce the problem? Use the Itemfinder anywhere there is a hidden item on screen.

jojobear13 commented 1 year ago

Fixed in c8a9dd9f95bff6cb4b6ac77b5c21dd4784003f83.

Looks like moving the OAM refresh to DelayFrame in order to solve stutter is causing some rare side effects elsewhere. This is one of them. It's because WaitForSoundToFinish runs right after reloading the overworld and updating the sprites, and that causes VBLANK to happen without doing any OAM updates.

EDIT:I have a sinking feeling there is something funky with the SS Anne cutscene too. I'll have to check that out.

Mord5 commented 1 year ago

I don't know what exactly you're looking for in terms of "something funky," but I checked it out and the S.S. Anne departure scene looks and sounds fine to me with the patch in place.

sinking feeling

I see what you did there

jojobear13 commented 1 year ago

I don't know what exactly you're looking for in terms of "something funky,"

It has to do with a certain quirk that's induced by doing Drenn's sprite wobble optimization in 707164a7bb2f640e92390cabe029ef657ac5993a. Any pokered hack that implements this will be affected. This quirk is thus:

Anytime you reload the overworld (like how it's done from exiting a menu), and then immediately after you call WaitForSoundToFinish, the overworld sprites will not load until the next time a DelayFrame call happens (such as inside OverworldLoop).

The reason is because Drenn's optimization moves the OAM update out of Vblank and into DelayFrame. You reload the main overworld which gets you back to the map. Then WaitForSoundToFinish happens, and Vblank interrupts occur within this. The Vblank interrupts update the sfx until its finished, but it's no longer updating the OAM; sprites aren't reloading onto the screen. Once all the sounds are finished playing, the regular overworld loop function happens and DelayFrame is called. It's only within DelayFrame that the OAM gets updated, and now the sprites all come back onto the screen.

I suspected the SS Anne because of the toot toot sound it plays while displaying the smoke sprites. Good to know nothing is wrong. My next suspicion is that without my fix from this issue, it would also cause sprites to disappear when waking up a snorlax with the pokeflute (menu exits and flute jingle starts to play). So one way or another this issue would have been found.