Skip to content

fix: Dolphin save states crash the emulation worker (segfault in retro_serialize) #342

Description

@ryanmagoon

Problem

Save states crash the emulation utility process when using the Dolphin (GameCube) libretro core. The worker terminates with a segfault during retro_serialize(), killing the entire emulation session.

Root Cause (confirmed via instrumentation)

The crash is inside Dolphin's retro_serialize() implementation — not in our GL setup or buffer allocation. Diagnostic logging confirms:

[gamelord] serialize: calling retro_serialize_size...
[gamelord] serialize: size=92409028 (88.1MB)
[gamelord] serialize: allocating 92409028 bytes...
[gamelord] serialize: calling retro_serialize...
[error] [ (ipc) ] Failed to save state: Error: Worker process terminated

We verified:

  • ✅ GL context is current (CGLSetCurrentContext)
  • ✅ FBOs are unbound (glBindFramebuffer(GL_FRAMEBUFFER, 0))
  • ✅ GL pipeline is flushed (glFinish())
  • ✅ Accumulated GL errors are drained
  • ✅ 88MB buffer allocation succeeds
  • ❌ retro_serialize() segfaults inside Dolphin's own code

The initial GL_INVALID_FRAMEBUFFER_OPERATION (0x0506) error was a red herring — draining it and unbinding FBOs didn't prevent the crash.

Current Mitigation

  • Save state UI is hidden for HW-render cores (saveStatesSupported flag piped from worker → renderer)
  • Worker-side guard blocks serialize/unserialize as defense-in-depth
  • No crash, no broken buttons — users simply don't see save state controls for GameCube

To Fix Properly

Investigate Dolphin's libretro retro_serialize implementation:

  • The crash is likely in GPU state serialization (texture cache, shader cache, or framebuffer readback)
  • May be specific to CGL offscreen contexts (no window backing)
  • May be specific to Apple Silicon / macOS OpenGL 4.1
  • Compare with how RetroArch sets up the GL context for Dolphin on macOS
  • Contribute fix upstream to libretro/dolphin

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions