SDL_SetWindowSize breaks rendering from SDL_Renderer

I have a program that creates a window and a software renderer, and will render to the screen every frame. If I try to change the width of the window to 800, it goes blank. A similar issue happens on Windows 11.

First window is a macOS window created at 640px width with no changes. Second window is a macOS window created at 640px width, but immediately after that, I change the width to 800. Third window is the same scenario as the second image, but on Windows 11.

I’d post code but I literally have no idea where to start, Google hasn’t given me any relevant clues and there are no errors in the console. What could be causing this?

How do you create the software renderer? Do you use SDL_CreateSoftwareRenderer or SDL_CreateRenderer?

I use SDL_CreateSoftwareRenderer.

If you’re passing the surface returned from SDL_GetWindowSurface as argument to SDL_CreateSoftwareRenderer that will be a problem because the docs says:

This surface will be invalidated if the window is resized. After resizing a window this function must be called again to return a valid surface.

You would essentially have to recreate the renderer to make it work again.

What you might want to do instead is create a software renderer for the window using SDL_CreateRenderer:

SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE)

That should make the renderer work even after the window has been resized. Note that if you do this you should not use SDL_GetWindowSurface / SDL_UpdateWindowSurface. The docs says so:

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


This works great, thanks!