Skip to content

Fix macOS save state crash in dual-core mode#428

Open
ryanmagoon wants to merge 1 commit into
libretro:masterfrom
ryanmagoon:fix-savestate-dualcore-crash
Open

Fix macOS save state crash in dual-core mode#428
ryanmagoon wants to merge 1 commit into
libretro:masterfrom
ryanmagoon:fix-savestate-dualcore-crash

Conversation

@ryanmagoon

@ryanmagoon ryanmagoon commented Apr 14, 2026

Copy link
Copy Markdown

In dual-core mode on macOS, retro_serialize and retro_unserialize queue DoState to the CPU thread via RunOnCPUThread. Frontends using an offscreen CGL context (no window-backed default framebuffer) set the GL context current on the calling thread, not the CPU thread. Any GL calls during DoState on the CPU thread segfault.

This temporarily declares the calling thread as the CPU thread so DoState runs inline where the GL context is valid.

Only tested on macOS arm64 with my own libretro frontend using an offscreen CGL context.

In dual-core mode, retro_serialize and retro_unserialize queue DoState
to the CPU thread via RunOnCPUThread. The CPU thread does not have the
frontend's GL context current, so any GL calls during DoState segfault.

Temporarily declare the calling thread as the CPU thread so DoState
runs inline where the GL context is valid.

Tested on macOS arm64 with a third-party libretro frontend using an
offscreen CGL context.
@ryanmagoon ryanmagoon changed the title Fix save state crash in dual-core mode Fix macOS save state crash in dual-core mode Apr 14, 2026
@cscd98

cscd98 commented Apr 20, 2026

Copy link
Copy Markdown

@warmenhoven are you able to test this please? as I don't have a mac

@JLiszt

JLiszt commented Jun 13, 2026

Copy link
Copy Markdown

It seems that this crash while loading states with dual core mode on is also happening in Android.

@LibretroAdmin

Copy link
Copy Markdown

Check if this applied on top makes this PR safer

0001-Use-CPUThreadGuard-for-save-state-instead-of-declari.patch

@cscd98

cscd98 commented Jun 24, 2026

Copy link
Copy Markdown

@LibretroAdmin Just tested this on linux, doesn't break anything so I'm happy for it to be merged.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants