mupen64plus-core icon indicating copy to clipboard operation
mupen64plus-core copied to clipboard

Paper Mario crash when loading save states

Open fzurita opened this issue 8 years ago • 50 comments

Paper Mario sometimes crashes when loading save states. I suspect that it's because save states don't contain the TLB state so it's not being re-enabled quickly enough. This crashes can happen when loading a save state and then pushing that start button.

This was a game crash, not a core crash, in game screenshot: screenshot_2016-10-16-13-41-23

fzurita avatar Oct 16 '16 17:10 fzurita

I forced using_tlb to 0 in the code but couldn't reproduce the issue. Do you have the savestate when the problem occurs?

BTW once set the using_tlb flag is only cleared on core shutdown, is this happening when using the resume option in mupen64plus-ae?

Gillou68310 avatar Oct 17 '16 12:10 Gillou68310

Yes, this is happening during the resume option. I can't seem to repeat it consistently, only sometimes. I'll see if I can find a way to make it happen more often.

fzurita avatar Oct 17 '16 12:10 fzurita

Damn I hate this resume option, we need to find a way to make it more predictable, for example only do a loadstate on first frame. This is what the --savestate option is doing btw.

Gillou68310 avatar Oct 17 '16 13:10 Gillou68310

See mupen64plus-ui-console for the --savestate option

Gillou68310 avatar Oct 17 '16 13:10 Gillou68310

Ok

fzurita avatar Oct 17 '16 13:10 fzurita

Why are we using M64CMD_STATE_LOAD instead of --savestate for resume? Any idea? It would be very easy to change to --savestate instead.

Also, is the "slot" functionality doing it correctly?

fzurita avatar Oct 17 '16 23:10 fzurita

The drawback of the --savestate option is that the first frame will be shown before the loadstate happens. I think @littleguy77 wanted to avoid this.

Also, is the "slot" functionality doing it correctly?

What do you mean?

Gillou68310 avatar Oct 18 '16 09:10 Gillou68310

You know how we have the option to save and load states using slots? I mean saving and loading using that functionality.

fzurita avatar Oct 18 '16 11:10 fzurita

You can't load slot using the --savestate option. You need to specify the path to the savestate --savestate C:\save.state

Gillou68310 avatar Oct 18 '16 12:10 Gillou68310

Ok

fzurita avatar Oct 18 '16 13:10 fzurita

Otherwise you can set your own frame callback coreDoCommand(M64CMD_SET_FRAME_CALLBACK, 0, (void*)MyFrameCallback) and do whatever you want inside it. You'll have to wait before M64CORE_EMU_STATE changed to M64EMU_RUNNING using OnStateCallbackListener before setting the callback.

Gillou68310 avatar Oct 19 '16 09:10 Gillou68310

OK, if you think that would get around this bug.

fzurita avatar Oct 19 '16 11:10 fzurita

I'm not saying that this will fix the issue. However with the --savestate option, the loadstate will always happen at the same moment, so if you manage to reproduce the issue once, the crash should happen every time you try to resume the corresponding savestate.

Gillou68310 avatar Oct 19 '16 12:10 Gillou68310

It's just that I won't be able to fix the issue if it's not 100% reproducible

Gillou68310 avatar Oct 19 '16 12:10 Gillou68310

The implementation is pretty simple:

if( !sIsRestarting )
{
    arglist.add( "--savestate" );
    arglist.add( saveToLoad );
}

and remove the whole block after the // Auto-load state if desired comment. We still have to find a way to avoid showing the first frame before the loadstate happens. You can test with dk64, the nintendo logo will always be shown before the loadstate happens.

Gillou68310 avatar Oct 19 '16 13:10 Gillou68310

@richard42 I'd like to change the --savestate option implementation. The idea is to load the savestate on the first safe state interrupt instead of loading it on the first frame. Do you think this is an acceptable solution?

Code here: https://github.com/Gillou68310/mupen64plus-core/commit/46654f26c927d2863d58680708ac7ed5c704f1e6 https://github.com/Gillou68310/mupen64plus-ui-console/commit/334db80b5559709905bd150b5f20fbf4c4005f49

Gillou68310 avatar Oct 19 '16 15:10 Gillou68310

I added the --savestate at startup option for my regression test framework (yet to be published):

https://github.com/mupen64plus/mupen64plus-ui-console/commit/566c9f9903592a1bda9a1e3f299537cb7027d9ac https://github.com/mupen64plus/mupen64plus-ui-console/commit/7d5247b3990a5b8232fb717af43355d10a2a3561 https://github.com/mupen64plus/mupen64plus-ui-console/commit/c495ff81e68a45b7c703629c20b88a5a56031a9f

The point is to work like this:

  • Load the state
  • Wait a given number of frame
  • Do a screenshot
  • Quit

The command is generated by a python script like this:

cmd = ["./mupen64plus",
   "--resolution", "640x480",
   "--audio", "dummy",
   "--configdir", os.path.join(current_dir, "config"),
   "--nosaveoptions",
   "--testshots", ",".join((str(f) for f in frames)),
   "--savestate", os.path.join(save_state_dir, "%s.st0" % test_name),
   "--sshotdir", tmp_screenshot_dir,
   rom_path]

I saw your code and it should work fine. I will try it asap and keep you in touch. :)

Narann avatar Oct 19 '16 18:10 Narann

I just tested. For an unknown reason, I have a black screen or no texture using --nosaveoptions with rice. mupen64plus-video-glide64mk2 doesn't seems to have any problem so I guess there is a problem with Rice options.

Anyway, It's ok for me. I suggest to do PR. :)

Narann avatar Oct 19 '16 20:10 Narann

Done ;-) What is the purpose of the --nosaveoptions in rice?

Gillou68310 avatar Oct 20 '16 09:10 Gillou68310

It's supposed to be a core option to do not save mupen64plus.cfg. I don't really understand why it create some troubles with rice.

Narann avatar Oct 21 '16 07:10 Narann

Can you confirm latest PR fixed you paper mario bug @fzurita? :)

Narann avatar Oct 21 '16 07:10 Narann

Sure, I'll check it out. This was not 100% reproducible, so it will be hard to 100% verify. But I will keep playing through Paper Mario and see if it happens again.

fzurita avatar Oct 21 '16 11:10 fzurita

Ok, I just had the in-game crash again after including the change to ui-console and the core. When I tried to manually load the saves state that caused it, it didn't crash... It's frustrating to reproduce the issue since it's so inconsistent.

fzurita avatar Oct 21 '16 15:10 fzurita

Did you change the resume implementation in m64p-ae to use the --savestate option?

Gillou68310 avatar Oct 22 '16 13:10 Gillou68310

Whoops, forgot that part.

fzurita avatar Oct 22 '16 13:10 fzurita

No problem ;-)

Gillou68310 avatar Oct 22 '16 13:10 Gillou68310

Ok, I haven't had it happen when resuming yet. But I just had it happen during a slot save. Here's is the slot save, just load it and push the N64 start button.

Paper Mario (U) [!].st0.zip

And saving a state in this condition causes a corrupt save state that causes the core to crash when being loaded:

2016-10-23-07-06-57.v2.sav.zip

fzurita avatar Oct 23 '16 11:10 fzurita

Ok, upon restarting the app and loading the save state. The game no longer crashes.

Also I couldn't get the app to stop crashing until I deleted all game data. I should have captured the core dump.

fzurita avatar Oct 23 '16 11:10 fzurita

Ok, I just had it happen after using the --savestate option. Once this in-game crash happens, it doesn't matter what states I load. Only way to recover is to kill then restart the app and I'm able to load the save state just fine and get into the in-game subscreen.

This crash only has happened after entering the in-game subscreen. To me, it seems that somehow TLB is not being activated sometimes.

Next time this happens, I'm going to try restarting by using reset, and see if it continues to happen.

Edit: Just happened again, I did a reset so the game would start over, loaded using the in-game save to load, then got into the in-game subscreen, and there was no crash. I think this confirms that TLB is not being enabled when loading a save state.

Why can't we save the TLB state as part of save states?

fzurita avatar Oct 23 '16 15:10 fzurita

Ok I confirm that this bug is caused by the using_tlb flag. When loading the first savestate you provided using the --savestate option I'm getting the issue 100% of the time.

sans titre

Initializing the using_tlb flag to 1 fix the issue. So like you said, the only way to fix this issue is to add the using_tlb flag to the savestate.

@Narann, @richard42 is the following solution ok for you? https://github.com/Gillou68310/mupen64plus-core/commit/22aa4f41b2c0354b260824a43d433ae3de81266f

Gillou68310 avatar Oct 24 '16 11:10 Gillou68310