[Gamecube] Memory Allocation error when loading savestate

Issue #468 new
Thiago Christovao created an issue

In old versions, this error rarely happened when trying to use save state in Mega CD games. In the latest version, it always happens to me.

I thought it was a problem because I was low on space compared to the total SD card(5/200gb).

But I recently used this space with the PC Engine CD emulator and games taking up 2gb. I didn't have any problems. Even using the save state of this emulator.

If I quit the game from Mega CD, start a game from Genesis, use save state, quit the game and go back to Mega CD, it is possible to use the function. But, in many cases, it is not possible to load unless you repeat the process.

I tried with both types of audio files(ogg/wav) and the same thing happens. The problem doesn't happen when I remove the audio files. Apparently...

I'm using the GameCube version. Using the save state at the beginning of the Ultraverse Prime stage reproduces the problem, for example.

Comments (12)

  1. Eke ekeeke repo owner

    This is not an issue caused by size available on SD card or the game size but because Gamecube has very limited RAM (only 24 MB) and most likely there is not enough RAM left to allocate the state buffer (which is around 1MB in size for Mega CD due to the amount of emulated hardware context and RAM to be saved). The state size has been increased 9 months ago I think to improve cd audio playback state restoration but that was only a few bytes more than before so I doubt this suddenly causes all savestates allocation to break. You should be able to see how much memory there is left before and after loading a game by going to exit menu from main menu. Unfortunately, I haven’t tested the gamecube build for a long time and I am not even sure my old gamecube is still operational so I cannot really provide continuous support as the emulator is evolving.

  2. Thiago Christovao reporter

    Limited RAM really is a problem. I needed to tweak some PC Engine CD games to work. But there is one detail that needs to be noted:

    This problem only occurs when I hit X amount of gb on the SD card and then I put the "genplus" folder with all the files. And I notice a slowness when using the program and loading games.

    I have defragged this card and noticed that the chances of writing the save state increase. But the reading problem remains.

    If I use my other card(64 gb) only with that emulator and the games, everything works perfectly.

    I'll check the amount of RAM anyway. Thanks.

  3. Thiago Christovao reporter

    I checked free memory. And I decided to put each ISO and audio files in separate folders.

    Now I can save in more than one slot. But I can't load.

    The memory value remains fixed: 3411952 bytes free.

    It happened that during the game exchange between the Mega CD and the Genesis it dropped to 20XXXXX. But it seems to happen rarely.

    That's it.

  4. Eke ekeeke repo owner

    This should be enough to temporarely allocate state buffer, even after taking savestate menu memory use (I checked and the max state size is actually 1036288 bytes).

    There are two possibilities for allocation error on state load: either the associated state screenshot takes too much memory or the savestate file size on sdcard is bigger than expected state size.

    You could check if it works better if you delete the savestate associated .png file (in /saves subdirectory on sd card) and also verify the savestate file size on sdcard is less than the max state size indicated above.

  5. Thiago Christovao reporter

    I will try this tomorrow. Thanks.

    I discovered something else that might be interesting:

    When I can save multiple slots without problem, I am also able to load the previous slot . The latter seems to “inherit” the problem.

    OGG is no longer an option for the GameCube. Memory drops to 20XXXXX bytes and unable to save/load.

    I decide to change the WAV files from 16 to 8 bit and see what happens. But, at first, it doesn't seem to change anything.

  6. Eke ekeeke repo owner

    WAV files are not loaded to RAM, they are only opened and read directly as a stream from storage device so reducing their size won’t do anything to RAM use. Also, the required format is 16 bit stereo PCM so reducing to 8 bit will break CD audio playback.

    OGG files take more memory because when they are opened, the ogg library (libtremor) allocates some buffer of unknown size for handling decompression, etc…

  7. Thiago Christovao reporter

    I suspected this because the amount of RAM didn't change after the change. My intention is to somehow facilitate the process.

    So far, all songs have run smoothly in 8-bit. I need to test a game to the end and verify this.

    I thought the only problem is using files at 22050hz.

  8. Thiago Christovao reporter

    The GP size is 1015909 bytes. The size on disk is 1048576 bytes. But I think the first value is what matters.

    Removing the PNG solved the problem.

    For now, I have two options: Manually delete the PNG always or create a 0 byte PNG file in read-only mode and never use the option to delete the save state.

  9. Eke ekeeke repo owner

    This explains what you have been experiencing:

    • if you load a savestate or try to save over an used slot, the savestate screenshot is loaded as a png file in memory which can significantly reduce available memory size
    • if you save in an empty slot, no png file is loaded in memory which increase the available memory size

    It is surprising though because from the reported available size (in exit menu), this means the decompressed png file takes more than 2MB in RAM, which seems a lot for a 320x224 pixels picture.

    Anyway, I guess a simple fix would be to unload the png from memory before loading or saving a state.

  10. Log in to comment