MacOS: fix for crash in SDL_Quit w/ gamepad input#16487
Conversation
|
We only want to init sdl once and quit sdl when rpcs3 is terminated. |
I agree this would be ideal.
I'm concerned that many or all of the other SDL operations run on the pad handler thread may also not be safe unless run on the same thread which calls init/quit. Even if not today some minor macOS update or internal SDL change may alter that. Any thoughts? |
|
I'm pretty sure that this is an upstream issue already. |
|
I can try that and see what happens, will report back |
8376b2c to
7526845
Compare
@Megamouse good news! simply calling init on the main thread as you suggest seems to work just fine for me, also solves the issue and is much simpler too. I've updated the PR with that change thanks. |
This PR refactors logic associated with SDL gamepads so that
SDL_Quitis called on the same thread which callsSDL_Initas a fix for crash at exit on macOS.The use-after-free bug this addresses occurs because some of the
IOKitobjects created duringSDL_Initare automatically torn down when the creating thread finishes leaving SDL with dangling pointers which may cause memory access faults during shutdown.For me this usually results in the error/backtrace below:
There may be other paths which cause SDL to access the dangling pointers or occasions where the memory is reallocated leading to more obscure bugs.
I've tested this on macOS but unfortunately don't currently have any equipment to test windows or linux builds on.