nipkownix / re4_tweaks

Fixes and tweaks for the "UHD" port of Resident Evil 4
zlib License
341 stars 32 forks source link

[Crash] Crash when alt-tabbing on item-examine screen, `IDirect3DDevice9::Reset` related #324

Closed emoose closed 2 years ago

emoose commented 2 years ago

As reported by @albertre4HD at https://github.com/nipkownix/re4_tweaks/issues/320#issuecomment-1225976828 (some more comments about it there too)

Hello! I think I've found a bug. When you take an item and I "Alt+TAB" the game while the item is rotating in the middle of the screen (game paused), the game crashes when I come back to the game. Here's the crash file: bio4.exe.20220824184120.zip

and tracked down by @nipkownix

Ah, if it only crashes when you Alt+Tab with full screen enabled, then it is probably triggered by IDirect3DDevice9::Reset. Might not be related to this hotkeys feature after all.

Edit: Ah, lol, it is caused by RestorePickupTransparency. We finally figured out why QLOC disabled it: They couldn't/didn't bother fixing this crash. Pffff.

nipkownix commented 2 years ago

Continuing from the other issue:

Isn't the X360 port also missing transparency? Maybe X360 had a similar problem when the guide menu was brought up or something like that.

According to Albert, the X360 port did have transparency. QLOC messed it up in the UHD port.

IIRC D3D9Ex usually helps improve alt-tabbing in most games that have option for it,

Would be nice if we could get D3D9Ex working in this game. Would probably make #268 possible too. Not sure how hard that would be, though.

of course would be better if we could maybe find a way to skip the pickup transparency stuff during alt-tab instead though...

Maybe, as a workaround, we can force-close the pickup screen when Reset is called?

emoose commented 2 years ago

dxvk seems promising, didn't crash the couple of times I tried it out, haven't tested it that much yet though. Of course that won't help people that can't use Vulkan though (or where Vulkan maybe performs worse...)

Maybe, as a workaround, we can force-close the pickup screen when Reset is called?

Worth a try, hopefully there won't be any timing related problems with it, could be worth seeing if we can make Reset set a flag that skips the GXCopyTex call inside ItemExamineHook - or maybe it would have to be set from whatever tells game device is lost? IIRC there is some code in the game that handles error code related to that, maybe we could handle that in the d3d9 hook stuff though.

E: aha, checking for D3DERR_DEVICELOST inside our hook_Direct3DDevice9::Present, and setting pConfig->bRestorePickupTransparency to false for it, seems to avoid the crash - you lose the transparency when alt-tabbing back in though, but that's pretty minor :p (E: actually that's probably because I forgot to add something to restore the bool, lel)

nipkownix commented 2 years ago

E: aha, checking for D3DERR_DEVICELOST inside our hook_Direct3DDevice9::Present, and setting pConfig->bRestorePickupTransparency to false for it, seems to avoid the crash

Ah, nice thinking with D3DERR_DEVICELOST! Should be a pretty simple workaround, then. Would still like to get EX working some day, though.

emoose commented 2 years ago

you lose the transparency when alt-tabbing back in though, but that's pretty minor :p (E: actually that's probably because I forgot to add something to restore the bool, lel)

Darn, restoring bool when D3D_OK didn't seem to help with that, I guess maybe item pickup screen stops the game behind it rendering it at all, and pickup is maybe taking a snapshot of it at the moment it was opened, but then device loss means that snapshot is lost until pickup screen is closed & reopened... too bad.

I'd guess 9Ex would be able to help with that since the buffer for snapshot should still exist AFAIK, probably worth looking into some time.

albertre4HD commented 2 years ago

Talking about that snapshot buffer. Just in case it helps at some point during your code research, the final cutscene uses it during a camera angle change: https://youtu.be/tTp-iSN6rr4?t=3487 Of course, this was lost in the HD ports I think this is the only place in the entire game it's used this way... interesting

albertre4HD commented 2 years ago

Oh, by the way, one of the issues this game has by default is also related to Alt+TAB the game. The flare lens effect gets bugged sometimes. https://youtu.be/CLhY4ruYvMU Could it be caused by the same problem?

nipkownix commented 2 years ago

Oh, by the way, one of the issues this game has by default is also related to Alt+TAB the game. The flare lens effect gets bugged sometimes.

Oh yeah, I was about to mention this one. Sounds like the same type of issue. Would be nice testing using DXVK to make sure.