SDL_HideWindow breaks SDL_RenderReadPixels() and/or SDL_RenderCopyEx, which is a problem for accelerated off-screen rendering

SDL_HideWindow breaks SDL_RenderReadPixels() and/or SDL_RenderCopyEx, which breaks accelerated off-screen rendering for applications that don’t want to present any sort of dedicated UI to the user, e.g. web backends.

The result is that on a hidden window, SDL_RenderReadPixels() will only return a black texture instead of the actual supposed proper contents, and it works fine as soon as the window is not hidden.

Since I use a lot of off-screen rendering in a backend and wanted to use SDL2 for this, it would be really nice if someone could look into this.

Here is the relevant ticket: https://bugzilla.libsdl.org/show_bug.cgi?id=3928

This isn’t actually an SDL problem I don’t believe; assuming you’re using the OpenGL backend?

You must render to a framebuffer to actually have the contents of the screen visible when the window is hidden.

See: https://www.khronos.org/opengl/wiki/Common_Mistakes#The_Pixel_Ownership_Problem

You should render to a render target-flagged texture if you aren’t already.