[32X] Doom 32X Resurrection v3.x exits with internal error
Describe the bug D32XR v3.x randomly fails to pass an internal safety check during the gameplay and exits with an error.
To Reproduce Steps to reproduce the behavior:
- Launch D32XR v3.x ROM
- Start a new map, preferrably MAP 1 or MAP 19
- Stand still for a bit
- See the following error message on the black background "lastopening > MAXOPENINGS: 4690"
The error involves some randomness or a few tries may be needed. Changing screen resolution to the maximum value seems to increase the odds of the error.
Expected behavior No errors.
Screenshots
Additional context
Please see https://github.com/viciious/d32xr/blob/master/r_main.c#L968
The 'lastopening' variable is a variable that is shared across two CPUs. The sanity check fails on the main CPU after the secondary CPU is done writing to it and corresponding cache line is flushed on the main CPU. This happens in ares, not on real hardware or other emulators. The problem may be related to bank switching, but I find that unlikely.
Note that this may still be a software issue, depending on how ares emulates SH2 CPU cache. I'll report back if I manage to fix it.