deltabeard / Peanut-GB

A Game Boy (DMG) emulator single header library written in C99. Performance is prioritised over accuracy.
https://projects.deltabeard.com/peanutgb/
276 stars 35 forks source link

Error 3 occurred: INVALID WRITE at FF7F #68

Closed YouMakeTech closed 1 year ago

YouMakeTech commented 1 year ago

Some games (e.g. Metroid II - Return of Samus (World)) trigger an error:

./peanut-sdl Audio driver: HDA NVidia Digital Stereo (HDMI) Unable to assign joystick mappings: Invalid RWops ROM: METROID2 MBC: 1 No palette found for 0x46. Error 3 occurred: INVALID WRITE at FF7F . Exiting. Cart RAM saved to recovery.sav

deltabeard commented 1 year ago

Which version/git commit of peanut_gb.h are you using? Did these games work before? Do the other games fail with the same error?

Thanks

YouMakeTech commented 1 year ago

The latest version of peanut_gb.h. These games did not work before unless I commented out the call to "abort()" in function gb_error. However, since the latest peanut_gb.h update, these games no longer start because of the "PGP_UNREACHABLE()" statements in peanut_gb.h right after each invocation of gb_error. In order to start the game now, I need to comment out all 'PGP_UNREACHABLE() statements in peanut_gb.h and comment out the call to "abort()" in function gb_error()

deltabeard commented 1 year ago

The PGP_UNREACHABLE() macro was added because some errors, like invalid opcode, aren't recoverable. However, some games to make invalid reads and writes that do not cause any issue on the real system. So I've removed the INVALID_WRITE error in commit 1278774cdcbc4384700480de6f35d93ab8b2f354 and Metroid II now works.