macOS Monterey Blank Black Window

I am trying to compile some basic examples with SDL2 on macOS 12 (Monterey) but have only managed to get a black window shown.

I have tried two methods:

  • Installing the SDL libraries with Homebrew and compiling a main file from the command line
  • Installing the SDL libraries as Frameworks and compiling a main file within an Xcode project.

In both cases, the test code I am using attempts to draw a rectangle on a white background:

#include <iostream>

#include <SDL2/SDL.h>

int main(int argc, char* argv[]) {
    SDL_Init(SDL_INIT_EVERYTHING);
    
    SDL_Window* window = SDL_CreateWindow("SDL Demo", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, SDL_WINDOW_SHOWN);
    SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);
    if (!renderer) {
        printf("Renderer could not be created! SDL Error: %s\n", SDL_GetError());
    }
    SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
    
    SDL_Rect r = { 0, 0, 10, 10 };
    SDL_Event event;
    
    bool quit = false;
    while (!quit) {
        
        while (SDL_PollEvent(&event) != 0) {
            if (event.type == SDL_QUIT) {
                quit = true;
            }
        }
        SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
        SDL_RenderClear(renderer);
        SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255);
        SDL_RenderFillRect(renderer, &r);
        SDL_RenderPresent(renderer);
    }
    
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();
}

However, I only get a black window.

When running the code from Xcode, I see error messages during runtime like this:

Execution of the command buffer was aborted due to an error during execution. Internal Error (e00002bd:Internal Error)

From what I can tell, these are errors specific to Xcode. I don’t get any SDL error messages or compilation errors from Xcode or when compiling directly from the command line.

I solved this simply by rebooting my computer. No idea what the original problem was!

1 Like