SDL_GetWindowSurface works with renderer on X11

I couldn’t find anything related to this and the closest post was this:

From the wiki: SDL_GetWindowSurface - SDL Wiki

You may not combine this with 3D or the rendering API on this window.

But it seems to work with X11 and also with a software renderer on wayland,
kmsdrm and X11.

Tested on the git version. Using sway for wayland and X11 (XWayland), dwm for
X11 and linux 5.18.10 for kmsdrm. And if it matters I’m using intel integrated

$ sdl2-config --version

Here’s a simple example that causes this problem.

#include <assert.h>
#include "SDL.h"

	int err = SDL_Init(SDL_INIT_VIDEO);
	assert(err >= 0);

	SDL_Window *w = SDL_CreateWindow("bug?", SDL_WINDOWPOS_UNDEFINED,
	assert(w != NULL);

	SDL_Renderer *r = SDL_CreateRenderer(w, -1, 0
	assert(r != NULL);

	SDL_Surface *s = SDL_GetWindowSurface(w);
	if (s == NULL) {
		SDL_Log("%s\n", SDL_GetError());

	return 0;

On wayland and kmsdrm it outputs: INFO: No hardware accelerated renderers available
and on X11 it works without errors.

When SDL_RENDERER_SOFTWARE is uncommented it seems to work fine.

I’m not sure what the “problem” is. The documentation states that you may not use both SDL_CreateRenderer() and SDL_GetWindowSurface() on the same window: you have to choose whether to use the rendering API or the surface API.

It doesn’t say that it definitely won’t work, just that it may not work (for example on some platforms and/or some backends) so you mustn’t rely on it.

So it’s like undefined behaviour and I can’t expect it to be consistent between different backends.

I guess I just misinterpreted the documentation. Thanks for the clarification.

This is almost inevitably the case for any abstraction layer supporting multiple platforms and backends. It can’t make them all behave identically, but it can define a documented subset of features that they will all support.