stride3d/stride · critical · Exception

Cannot allocate SDL Window:

Error message

Cannot allocate SDL Window: 

What it means

In the SDL Window constructor, if SDL.CreateWindow returns a null handle, the window could not be allocated and the constructor throws a generic Exception including SDL.GetErrorS() which carries the underlying SDL error text (e.g. no video driver, display unavailable).

Solutions

  1. Read the appended SDL.GetErrorS() text for the root cause
  2. Ensure a display/video driver is available: set DISPLAY (X11), or SDL_VIDEODRIVER=dummy/offscreen for headless runs
  3. Install/repair graphics drivers and SDL runtime dependencies
  4. Verify SDL was initialized before window creation

Example fix

// before (CI without display)
dotnet run --project Game
// after
SDL_VIDEODRIVER=dummy dotnet run --project Game
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("DISPLAY")) && Environment.OSVersion.Platform != PlatformID.Win32NT) throw new InvalidOperationException("No display available for SDL window");

Try / catch

try { var win = new Window(...); } catch (Exception ex) when (ex.Message.StartsWith("Cannot allocate SDL Window")) { log.Error(ex.Message); }

Prevention

When it happens

Trigger: Constructing a Stride.SDL Window when SDL_CreateWindow fails: missing display, no usable video driver (e.g. headless environment without dummy driver), or invalid window flags.

Common situations: Running on a headless CI server with no DISPLAY/WAYLAND_DISPLAY set, SDL video subsystem initialization failure, or missing graphics drivers in containers.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/3f29195486bc85d1. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Graphics/SDL/Window.cs:102

#endif

            // If there is a parent hwnd
            if (parent != IntPtr.Zero)
            {
                void* parentPtr = parent.ToPointer();

                sdlHandle = SDL.CreateWindowFrom(parentPtr);
            }
            else // no parent window
            {
                // Create the SDL window and then extract the native handle.
                sdlHandle = SDL.CreateWindow(title, Sdl.WindowposUndefined, Sdl.WindowposUndefined, 640, 480, (uint)flags);
            }
            

            if (sdlHandle == null)
            {
                throw new Exception("Cannot allocate SDL Window: " + SDL.GetErrorS()); 
            }

            SysWMInfo info = default;
            SDL.GetVersion(&info.Version);
            if (!SDL.GetWindowWMInfo(sdlHandle, &info))
            {
                throw new Exception("Cannot get Window information: " + SDL.GetErrorS());
            }

            if (Core.Platform.Type == Core.PlatformType.Windows)
            {
                Handle = info.Info.Win.Hwnd;
            }
            else if (Core.Platform.Type == Core.PlatformType.Linux)
            {
                Handle = (IntPtr)info.Info.X11.Window;
                Display = (IntPtr)info.Info.X11.Display;
            }

View on GitHub (pinned to 96fad776d2)