Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emulator crashes when trying to load a save state #65

Open
autofire372 opened this issue Jan 16, 2017 · 33 comments
Open

Emulator crashes when trying to load a save state #65

autofire372 opened this issue Jan 16, 2017 · 33 comments
Assignees

Comments

@autofire372
Copy link

@autofire372 autofire372 commented Jan 16, 2017

Please fill out this form:

Expected behavior

The previously saved state is loaded.

Actual behavior

The emulator crashes to desktop.

Steps to reproduce the behavior

Open a game. Make a save state, and then attempt to load it (i.e. hit Shift+F1 and then F1). The program should then crash.

Build details

Operating System (Windows, Mac, Linux, etc.):
Windows 10 x64
Interface (wx, SDL, default is wx):
wx
Version of code (pre-built binary version, or commit ref, or just "master"):
master
Any other relevant build information:

If this is e.g. a joystick or video issue, then the relevant hardware information:

@ichigo-0

This comment has been minimized.

Copy link

@ichigo-0 ichigo-0 commented Feb 7, 2017

In my case, it is inconsistent. Sometimes it crashes when I try to load a saved state, but if I relaunch and try again, it will often load that state successfully. I don't think I've yet found a save that couldn't be loaded (but initially I assumed the save states were corrupt and after a crash would try to load a different state).

(If the first load succeeds, loading the same state a few more times generally can produce a crash for me.)

I'm also using master (fcc3439), though I'm on Linux.

Possibly related are crashes when saving state. These crashes seems to happen after the save completes (because I can load it successfully later).

UPDATE: Apparently whenever I post about a problem, it will magically fix itself shortly thereafter. In this case, I had another issue that caused me to reset my vbam.ini file, after which I seem to no longer be able to make it crash. The problem here is that I still have the old vbam.ini file, and using that again recreates the other issue, but I still can't make it crash.

So, apparently I don't have this problem anymore, but I have no idea what made it go away, and thus have no useful advice for other people who might experience it. Sorry.

@rkitover rkitover added the bug label Feb 10, 2017
@TheDauthi

This comment has been minimized.

Copy link

@TheDauthi TheDauthi commented Feb 16, 2017

I'm seeing the same behavior - inconsistent crashes to desktop on save file loading. (I also see the same problem with saves).

Upon regenerating the ini file, the first time I loaded a save state, the emulator crashed. Upon reopening, it no longer crashes.

@rkitover

This comment has been minimized.

Copy link
Collaborator

@rkitover rkitover commented Feb 16, 2017

Apparently there's an issue with the current save code in that it incorrectly determines the flash size for some ROMs, this is known to be a bug with normal saves, but it may be affecting state saves as well.

@Squall-Leonhart

This comment has been minimized.

Copy link

@Squall-Leonhart Squall-Leonhart commented Apr 7, 2017

it would not be affecting save states, the issue at large is because vba-m writes to the config file when a state is loaded.

@kvaak

This comment has been minimized.

Copy link

@kvaak kvaak commented Apr 15, 2017

64-bit Win10, latest GitHub release. I'm not sure whether it's related to this issue at all, but since it involves broken save states I'm going to assume so. My save states load just fine, problem is they seem to consist of glitchy garbage that makes Sinclair Spectrum loading screens sound like an opera. ROM is European version of FF6 Advance with a sound restoration patch glued on top.

SOUND WARNING. SERIOUSLY, TAKE OFF YOUR HEADPHONES.

https://www.youtube.com/watch?v=Rpiric_J16U

Towards the end of the video you can see how it claims to load the glitched states but instead of sending Celes back to the desk she keeps walking around the room like nothing happened. The two "intact" save states were created with the latest Sourceforge release of VBA-M - any save states created with it can be loaded without problems with the GitHub version. The Sourceforge version crashes at random upon saving, randomly upon loading or just at random though.

I've tried at least the following and probably a bunch of other stuff I can't recall off the top of my head:

  • Deleting the configuration file.
  • Running as administrator and/or in compatibility mode.
  • Deleting all saves, both .sav and .sgm, doing a fresh start, saving in the main menu screen etc.
  • Disabling the patch.
  • Running the debug version. It doesn't produce any messages after the save state is loaded (or saved), seemingly assuming everything is in order.

E: Also, all the broken save states are EXACTLY 8192 bytes, whereas the working ones are all 100+ KB.

@Calmarius

This comment has been minimized.

Copy link

@Calmarius Calmarius commented Jul 10, 2017

The cause of the crash is an uninitialized value. I ran the emulator within valgrind and I have an exact place where this occur. The behavior depends on what memory junk happens to be at the uninitied location...

==4418== Conditional jump or move depends on uninitialised value(s)
==4418==    at 0x520241: GameArea::LoadState(wxFileName const&) (panel.cpp:581)
==4418==    by 0x520956: GameArea::LoadState(int) (panel.cpp:573)
==4418==    by 0x4ED846: MainFrame::DoLoadGame01() (cmdevents.cpp:1415)
==4418==    by 0x4ED85D: MainFrame::OnLoadGame01(wxCommandEvent&) (cmdevents.cpp:1413)
==4418==    by 0x74E21FD: wxAppConsoleBase::CallEventHandler(wxEvtHandler*, wxEventFunctor&, wxEvent&) const (in /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0.2.0)
==4418==    by 0x76686E6: wxEvtHandler::ProcessEventIfMatchesId(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) (in /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0.2.0)
==4418==    by 0x76687DA: wxEventHashTable::HandleEvent(wxEvent&, wxEvtHandler*) (in /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0.2.0)
==4418==    by 0x7668B8A: wxEvtHandler::TryHereOnly(wxEvent&) (in /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0.2.0)
==4418==    by 0x7668C12: wxEvtHandler::ProcessEventLocally(wxEvent&) (in /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0.2.0)
==4418==    by 0x7668C74: wxEvtHandler::ProcessEvent(wxEvent&) (in /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0.2.0)
==4418==    by 0x7084DE7: wxWindowBase::TryAfter(wxEvent&) (in /usr/lib/x86_64-linux-gnu/libwx_gtk2u_core-3.0.so.0.2.0)
==4418==    by 0x76689E6: wxEvtHandler::SafelyProcessEvent(wxEvent&) (in /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0.2.0)
==4418==  Uninitialised value was created by a heap allocation
==4418==    at 0x4C2E0EF: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==4418==    by 0x52CE75: GameArea::wxCreateObject() (panel.cpp:18)
==4418==    by 0x617CF51: wxXmlResourceHandlerImpl::CreateResource(wxXmlNode*, wxObject*, wxObject*) (in /usr/lib/x86_64-linux-gnu/libwx_gtk2u_xrc-3.0.so.0.2.0)
==4418==    by 0x61866E8: wxXmlResource::DoCreateResFromNode(wxXmlNode&, wxObject*, wxObject*, wxXmlResourceHandler*) (in /usr/lib/x86_64-linux-gnu/libwx_gtk2u_xrc-3.0.so.0.2.0)
==4418==    by 0x61336E4: wxSizerXmlHandler::Handle_sizeritem() (in /usr/lib/x86_64-linux-gnu/libwx_gtk2u_xrc-3.0.so.0.2.0)
==4418==    by 0x617CD97: wxXmlResourceHandlerImpl::CreateResource(wxXmlNode*, wxObject*, wxObject*) (in /usr/lib/x86_64-linux-gnu/libwx_gtk2u_xrc-3.0.so.0.2.0)
==4418==    by 0x61866E8: wxXmlResource::DoCreateResFromNode(wxXmlNode&, wxObject*, wxObject*, wxXmlResourceHandler*) (in /usr/lib/x86_64-linux-gnu/libwx_gtk2u_xrc-3.0.so.0.2.0)
==4418==    by 0x61876B6: wxXmlResourceHandlerImpl::CreateChildren(wxObject*, bool) (in /usr/lib/x86_64-linux-gnu/libwx_gtk2u_xrc-3.0.so.0.2.0)
==4418==    by 0x61331BB: wxSizerXmlHandler::Handle_sizer() (in /usr/lib/x86_64-linux-gnu/libwx_gtk2u_xrc-3.0.so.0.2.0)
==4418==    by 0x617CD97: wxXmlResourceHandlerImpl::CreateResource(wxXmlNode*, wxObject*, wxObject*) (in /usr/lib/x86_64-linux-gnu/libwx_gtk2u_xrc-3.0.so.0.2.0)
==4418==    by 0x61866E8: wxXmlResource::DoCreateResFromNode(wxXmlNode&, wxObject*, wxObject*, wxXmlResourceHandler*) (in /usr/lib/x86_64-linux-gnu/libwx_gtk2u_xrc-3.0.so.0.2.0)
==4418==    by 0x61876B6: wxXmlResourceHandlerImpl::CreateChildren(wxObject*, bool) (in /usr/lib/x86_64-linux-gnu/libwx_gtk2u_xrc-3.0.so.0.2.0)
==4418== 

rkitover added a commit that referenced this issue Aug 17, 2017
Rewrite SoundSDL (the SDL sound driver).

Clean up the code and eliminate all deadlocks/hangs/crashes (hopefully.)

Many of the deadlocks were caused by initialize() not de-initializing
properly and causing the audio callback thread to deadlock, fix this.

Also use better logic for the semaphore controls, which will also
hopefully increase audio quality.

Use better logic for the throttle control, with throttle == 0 being the
same as throttle == 100 and implement setThrottle().

Also increase the buffer size to 300ms and the number of samples to
2048, for hopefully less choppiness in audio overall.
@RhinoKneel

This comment has been minimized.

Copy link

@RhinoKneel RhinoKneel commented Sep 16, 2017

I feel what could be happening to the .sgm files is the emulator is writing all it can to a file given a limited size. While not a GBA test, I noticed from 3 separate states from Pokemon Yellow, no matter the recorded size, size on disk was 8,192.
The state saved on the title screen is 5,482, Checking my save info and going back, it went up to 6,337. As mentioned by @kvaak though, when I saved after loading into Cerulean City, it matched 8,192 and would just freeze if you tried to load it.
I did experiment using the regular VBA emulator, saving a save state in the same location and loading it with VBA-M. The state saved as an 8,184 file, 8 bytes from the error size. When loading in VBA-M, it runs, but all the sprite layer entities were just black and white.

Also compared file size for GBA. While VBA-M is saving with a size of disk of 8,192, I noticed VBA saved with 53,248. I feel the very bad glitches in terms of visuals and sound could be it's trying to find data on a file 6.5 times smaller.

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Mar 11, 2018

I don't know if helps. I turn off sound in game options, after 8 times trying save state and reload a importante mission. Works for me.

@rkitover

This comment has been minimized.

Copy link
Collaborator

@rkitover rkitover commented Mar 12, 2018

@DeepNavyBlue could you please check if having the SDL sound driver as opposed to another one works?

@nwawrzyniak

This comment has been minimized.

Copy link

@nwawrzyniak nwawrzyniak commented Aug 19, 2018

Switching to SDL worked like a charm to me! I had the same problem (all problematic save files were exactly 8192 Bytes (8KB) big while smaller ones always seemed to load properly) and since I set my audio device to SDL and recorded a new save state (because loading the old one resulted in even heavier crashes) the save file loading function seems much more stable. Before it often crashed when trying to load save states quite quickly again and again or when certain variables in games were messed with in a way that is no problem for real hardware.

EDIT: Just saw this thread is a little older and I use the current version of VBA-M. I'm not sure but I think for GBA games the default sound device is set to DirectSound. Maybe the default option should be set to SDL for future releases until this behaviour has been adressed?

@L0ST5ILVER

This comment has been minimized.

Copy link

@L0ST5ILVER L0ST5ILVER commented Aug 27, 2018

Switching to SDL did not work at all for me, the issue still persists. Can anyone help please?

@L0ST5ILVER

This comment has been minimized.

Copy link

@L0ST5ILVER L0ST5ILVER commented Sep 2, 2018

Hello? Can somebody please help. This glitch has been around for ages and it's making playing borderline unplayable having to force close the emulator every time I want to load a state, then having to roll the dice and hope it doesn't crash next time I load it.

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Sep 2, 2018

@L0ST5ILVER

  • are you using the latest version of vba-m?
  • are you loading state taken from the same version and from the same game?
  • are using windows or linux?

let me remind that the git page is for reporting bugs, and not a help me center.
thanks.

@L0ST5ILVER

This comment has been minimized.

Copy link

@L0ST5ILVER L0ST5ILVER commented Sep 2, 2018

Yes.
Yes.
Windows 10.

I AM reporting a bug, I worded it poorly by using "help".

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Sep 2, 2018

post the exact name of the game ( load the game, and go to file > rom information ) screenshot that and paste here. upload also the last savestate files and the save file for the game and somebody might be able to look into it (i dont have windows atm and time constraints)

@L0ST5ILVER

This comment has been minimized.

Copy link

@L0ST5ILVER L0ST5ILVER commented Sep 2, 2018

image
It is a Pokémon Red hack called "Pokémon Red Deluxe" (Or DX)

Save state is here: http://www.mediafire.com/file/adml4mh0x735r83/Pokemon_Red_DX.sgm/file

Edit: Just tested, same crash happens in none hacked versions of Pokémon and also for any game that I load with the emulator.

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Sep 2, 2018

ugh... more of this DX gb games. if this is some sort of colorized hack, i wont get my hopes up...

is the save file not viable?

@L0ST5ILVER

This comment has been minimized.

Copy link

@L0ST5ILVER L0ST5ILVER commented Sep 2, 2018

The save file works fine, it can just take several times to load, several crashes.
As stated before, this issues persists with authentic, none hacked versions of Pokémon, and even normal GBA games.

@Photon89

This comment has been minimized.

Copy link

@Photon89 Photon89 commented Jun 30, 2019

Another "me too" (Fire Emblem, Arch Linux, sound set to SDL, a state can crash several times but then load without problem). The verbose mode sometimes gives me

free(): invalid pointer

or

corrupted double-linked list

or

double free or corruption (out)

as output during the crash.

@denisfa

This comment has been minimized.

Copy link
Collaborator

@denisfa denisfa commented Jun 30, 2019

@Photon89 do you mind adding a save state that run into this issue? I am trying to debug this, but failing to do so. I tried the pokemon games (original), but also could not get this. Which FE game did you try?

If you don't mind, add you vbam.ini please. I am suspicious about the cause, but can't properly confirm.

@Photon89

This comment has been minimized.

Copy link

@Photon89 Photon89 commented Jun 30, 2019

@denisfa Thanks for the fast reply! It is just called "Fire Emblem", from 2003. Please find the two files attached.
vbam.tar.gz

@denisfa denisfa added this to To Do in release v2.1.7 via automation Jun 30, 2019
@denisfa denisfa self-assigned this Jun 30, 2019
@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Jun 30, 2019

@Photon89 looks like a language issue, based on the config file included... and why play on "simple" rendering? Anyways lemme see if i find something using your state file...

  • btw which fire emblem is this? show rom information screenshot.
  • nvm its an AE7E version, so its the US one. your state loads fine. how many time did you try reloading or if it does load at all in your end.

Anyways cant replicate in on Linux. this must be a windows issue thing, which i dont have atm...
Screenshot

@denisfa

This comment has been minimized.

Copy link
Collaborator

@denisfa denisfa commented Jul 1, 2019

@retro-wertz It is a Linux issue too. It failed for me on Linux. I tried 3 times before the bug appeared.

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Jul 1, 2019

any config change you guys using? like custom flash size or whatnot? (in on a clean install, other than custom folders and input keybinds) anyways i tried loading different states and its not a problem, so far on me at least.

@denisfa

This comment has been minimized.

Copy link
Collaborator

@denisfa denisfa commented Jul 1, 2019

@retro-wertz No, nothing special. I just use his vbam.ini and tried to load state a couple of times. I think I know where the issue is, although it is quite weird that you can't reproduce it. Also I am using the master branch build.

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Jul 1, 2019

where is is? on gba.cpp or on the wx stuff

nvm. anyways simple rending crashes states.. GL does not (at least for me)
https://hastebin.com/ulaqumivek.php
dunno why using simple rendering corrupts gzclose. anyways there should be an option at least to support sram files in its raw save format.

ASA is pointing to panel.cpp line 1738 to be the problem
https://hastebin.com/ikukoxekih.coffeescript

cant remember if this was a problem before since i never run with simple rendering...

@denisfa

This comment has been minimized.

Copy link
Collaborator

@denisfa denisfa commented Jul 1, 2019

@retro-wertz Not so sure about it yet... I believe it can't be just that, since the behaviour for breaking or not (as the error messages) is all over the places. I run into this after 3 times on my first reply, but now had to try 11.Got 2 different error messages while doing so (double free vs realloc fail).

You are reporting ASAN issues, that should take a separate thread. This may or may not be the cause here.

cant remember if this was a problem before since i never run with simple rendering...

This thread split on several issues over time. Probably it was always a thing.

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Jul 1, 2019

the asan issue i posted on glitter (or was it griiter) uses more asan options, which i normally use. its not suppose to crash the last time this asan was added...

the asan i posted here is caused when loading.saving the states. this is only using -fsanitize=address instead of my usual address,undefined. anyways im just giving out my data. if its unrelated i dont mind..

@Photon89

This comment has been minimized.

Copy link

@Photon89 Photon89 commented Jul 1, 2019

Not sure if still any input is required/helpful from my side after your discussion, let me know if I can do anything else to help track down the issue!

@denisfa

This comment has been minimized.

Copy link
Collaborator

@denisfa denisfa commented Jul 1, 2019

@Photon89 Thank you for all the extra info. We will try to solve this now.

@retro-wertz The issue is indeed memory corruption. But it is not a random behaviour, it happens due to allocated size being smaller than required. When you compare the OpenGL and Simple allocation size, the first is bigger and I also failed to reproduce this issue with OpenGL. It is on this line of src/wx/panel.cpp:

pixbuf2 = (uint8_t*)calloc(allocstride, std::ceil((alloch + 2) * scale));

If you try to change to increase its size, let's say double it calloc(allocstride, 2 * std::ceil((alloch + 2) * scale)), it works again. Also, I open the game with Simple method and create a dummy save state on F2 while in the opening. If i try to load it, it crashes immediately (showing a variety of error messages). If I switch to OpenGL and try this very save state, it works correctly no matter how many times I press F2.

Any ideas about how to properly tackle this? I will set a branch for this, so we can point out code more easily.

denisfa added a commit that referenced this issue Jul 1, 2019
It looks like that when we use the `Simple` output module, we get
weird errors when trying to load state for any game, most likely due to
memory corruption. AFAIK, it seems the frame buffer is not large enough
to render all components.

This issues does not appear when using OpenGL, or using the Simple with
any display filter available.
@denisfa denisfa moved this from To Do to In Progress in release v2.1.7 Jul 1, 2019
denisfa added a commit that referenced this issue Jul 1, 2019
It looks like that when we use the `Simple` output module, we get
weird errors when trying to load state for any game, most likely due to
memory corruption. AFAIK, it seems the frame buffer is not large enough
to render all components.

This issues does not appear when using OpenGL, or using the Simple with
any display filter available.
@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Jul 1, 2019

the question there is why is it writting dimensions based on GB/SGB when we are suppose to be running GBA.

bpp is a question as well. im not the right person to tag for wx/api function but vbam was suppose to be using 32bpp modes only for shader compatibility.

@denisfa

This comment has been minimized.

Copy link
Collaborator

@denisfa denisfa commented Jul 1, 2019

the question there is why is it writting dimensions based on GB/SGB when we are suppose to be running GBA.

This does not matter. It can be scaled to any size. The big thing is the params from the calloc.

bpp is a question as well. im not the right person to tag for wx/api function but vbam was suppose to be using 32bpp modes only for shader compatibility.

On the code it is stated that all filters are either 16 or 32 bpp. Is the value 24 because of the gba hardware? Same thing for GB? I have no clue about this. Neither can I notice the difference between 24 and 32... I need pointers so I know I am not ruining everything.

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Jul 1, 2019

rkitover added a commit that referenced this issue Jul 3, 2019
It looks like that when we use the `Simple` output module, we get
weird errors when trying to load state for any game, most likely due to
memory corruption. AFAIK, it seems the frame buffer is not large enough
to render all components.

This issues does not appear when using OpenGL, or using the Simple with
any display filter available.
@denisfa denisfa mentioned this issue Jul 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
release v2.1.7
  
In Progress
You can’t perform that action at this time.