libretro / swanstation

GNU General Public License v3.0
96 stars 22 forks source link

Certain RetroAchievements Causing Crashes #16

Closed nickkeane closed 2 years ago

nickkeane commented 2 years ago

Certain RetroAchievements seem to be causing the emulator to crash when triggered.

Achievements Tested w/:

SwanStation Git#0932243, RetroArch 1.10.0 Using Beetle PSX HW seems to be unlocking achievements w/ no issues so far, so idk if there's a difference in how they're processing achievements vs SwanStation. https://github.com/libretro/beetle-psx-libretro https://docs.retroachievements.org/libretro-core-support/

Some achievements seem to work while others crash in SwanStation. Once I unlocked an achievement via Beetle PSX HW on my account, it didn't cause an issue in SwanStation going forward.

nickkeane commented 2 years ago
// Beetle PSX git#88929ae 
// File libretro.cpp | Line 5021
void *retro_get_memory_data(unsigned type)
{
   uint8_t *data;

   switch (type)
   {
      case RETRO_MEMORY_SYSTEM_RAM:
         return MainRAM->data8;
      case RETRO_MEMORY_SAVE_RAM:
         if (!use_mednafen_memcard0_method)
            return PSX_FIO->GetMemcardDevice(0)->GetNVData();
         break;
      default:
         break;
   }
   return NULL;
}

size_t retro_get_memory_size(unsigned type)
{
   switch (type)
   {
      case RETRO_MEMORY_SYSTEM_RAM:
         return 0x200000;
      case RETRO_MEMORY_SAVE_RAM:
         if (!use_mednafen_memcard0_method)
            return (1 << 17);
         break;
      default:
         break;
   }

   return 0;
}

// SwanStation git#0e27584
// File main.cpp | Line 112
RETRO_API void* retro_get_memory_data(unsigned id)
{
  return g_libretro_host_interface.retro_get_memory_data(id);
}

RETRO_API size_t retro_get_memory_size(unsigned id)
{
  return g_libretro_host_interface.retro_get_memory_size(id);
}

// File libretro_host_interface.cpp | Line 646
void* LibretroHostInterface::retro_get_memory_data(unsigned id)
{
  switch (id)
  {
    case RETRO_MEMORY_SYSTEM_RAM:
      return System::IsShutdown() ? nullptr : Bus::g_ram;

    case RETRO_MEMORY_SAVE_RAM: {
      const MemoryCardType type = g_settings.memory_card_types[0];
      if (System::IsShutdown()  || type != MemoryCardType::Libretro) {
        return nullptr;
      }
      auto card = g_pad.GetMemoryCard(0);
      auto& data = card->GetData();
      return data.data();
      break;
    }

    default:
      return nullptr;
  }
}

size_t LibretroHostInterface::retro_get_memory_size(unsigned id)
{
  switch (id)
  {
    case RETRO_MEMORY_SYSTEM_RAM:
      return Bus::g_ram_size;

    case RETRO_MEMORY_SAVE_RAM: {
      const MemoryCardType type = g_settings.memory_card_types[0];
      if (System::IsShutdown()  || type != MemoryCardType::Libretro) {
        return 0;
      }
      return 128 * 1024;
    }

    default:
      return 0;
  }
}

Not sure if there are differences that could be causing the issue somewhere in here, I don't have a debugging env set up atm.

DarthMew commented 2 years ago

What type of memory card are you using, srm or mcd? Also, is the Medievil crash consistant on your end, because when I tried it on my Windows 10 PC, using RetroArch 1.10.3, latest version of SwanStation, and using Libretro sram as the memory card type, the achievement unlocked just fine.

nickkeane commented 2 years ago

srm

DarthMew commented 2 years ago

And could you tell me what operating system you're running RetroArch on (I.E. Windows, Linux etc.), and if the crash with Medievil is consistent or not? Also, just to eliminate this as a possibility, but do these crashes also happen with RetroArch 1.10.3?

nickkeane commented 2 years ago

Windows, it was consistently crashing until i unlocked the achievement with Beatle PSX HW core, then after being unlocked it doesn't crash again in SwanStation. I can't retest that particular achievement since it's already unlocked.

DarthMew commented 2 years ago

Inside of RetroArch's achievements options, there should be an option to enable encore mode, which should allow you to start the game with all achievements active.

nickkeane commented 2 years ago

I found out how to reset achievements per game from the website, it worked this time (for the Medievil copper shield), so maybe the issue was w/ RetroArch being outdated.