We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5046

Summary: Crash on window resize when rendering on another thread
Product: SDL Reporter: Emir Marincic <learath2>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 2.0   
Hardware: x86   
OS: macOS 10.15   
Attachments: performSelectorOnMainThread patch

Description Emir Marincic 2020-03-20 08:56:40 UTC
Created attachment 4271 [details]
performSelectorOnMainThread patch

Resizing a window schedules an update on the SDLOpenGLContext, the next swap on the auxiliary thread doing the rendering causes a [NSOpenGLContext update] on that thread, which is not allowed.

[NSOpenGLContext update] only started checking whether it's called from the main thread (through pthread_main_np) from Catalina onwards and AppKit uses _CFExecutableLinkedOnOrAfter to provide compatibility for older executables by setting NSOpenGLContextSuppressThreadAssertions.

I'm not sure if this should be supported but swapping on a separate thread works on enough platforms that we didn't notice this bug for years. Calling update on the main thread instead through performSelectorOnMainThread seems to work fine and after testing a couple of hours I didn't notice any undesired effects.

I've attached the patch I've been testing locally

Best regards
Emir
Comment 1 Sam Lantinga 2020-03-20 19:10:23 UTC
Looks good, thanks!
https://hg.libsdl.org/SDL/rev/c8f27a5e868e