diff --git a/OpenRA.Platforms.Default/Sdl2GraphicsContext.cs b/OpenRA.Platforms.Default/Sdl2GraphicsContext.cs index 81152c302f..b6fdc82fa8 100644 --- a/OpenRA.Platforms.Default/Sdl2GraphicsContext.cs +++ b/OpenRA.Platforms.Default/Sdl2GraphicsContext.cs @@ -25,15 +25,20 @@ namespace OpenRA.Platforms.Default public Sdl2GraphicsContext(Sdl2PlatformWindow window) { this.window = window; + + // SDL requires us to create the GL context on the main thread to avoid various platform-specific issues. + // We must then release it from the main thread before we rebind it to the render thread (in InitializeOpenGL below). + context = SDL.SDL_GL_CreateContext(window.Window); + if (context == IntPtr.Zero || SDL.SDL_GL_MakeCurrent(window.Window, IntPtr.Zero) < 0) + throw new InvalidOperationException($"Can not create OpenGL context. (Error: {SDL.SDL_GetError()})"); } internal void InitializeOpenGL() { SetThreadAffinity(); - context = SDL.SDL_GL_CreateContext(window.Window); - if (context == IntPtr.Zero || SDL.SDL_GL_MakeCurrent(window.Window, context) < 0) - throw new InvalidOperationException($"Can not create OpenGL context. (Error: {SDL.SDL_GetError()})"); + if (SDL.SDL_GL_MakeCurrent(window.Window, context) < 0) + throw new InvalidOperationException($"Can not bind OpenGL context. (Error: {SDL.SDL_GetError()})"); OpenGL.Initialize(window.GLProfile == GLProfile.Legacy); OpenGL.CheckGLError();