Discussion:
[SDL] Target textures getting randomly swapped on window resize !!
sgrsgsrg
2016-09-15 00:59:58 UTC
Permalink
Please, compile this little program and look what happens when you resize the window. Basically, i create two coloured textures, and i display only the second. For some reason SDL will toggle between textures A and B every time you resize the window !!! [Shocked]
You can even have more fun creating 4 textures (A, B, C, D) and doing renderCopy on D to see SDL switching between all of them from the last to the first.
Interestingly, it works only backwards, i mean if you have 4 target textures and telling sdl to display the 1st, it'll only display the 1st. If you tell to display the 2nd, it'll switch between 1st and 2nd...

WTF is happening rly...


Code:

#include <SDL.h>

int main(){
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* window = SDL_CreateWindow("test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 200, 200, SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);

SDL_Texture* a = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_BGRA4444, SDL_TEXTUREACCESS_TARGET, 50, 50);
SDL_SetRenderTarget(renderer, a);
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
SDL_RenderFillRect(renderer, NULL);

SDL_Texture* b = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_BGRA4444, SDL_TEXTUREACCESS_TARGET, 50, 50);
SDL_SetRenderTarget(renderer, b);
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
SDL_RenderFillRect(renderer, NULL);

SDL_SetRenderTarget(renderer, NULL);
SDL_Event e;

while (1){
SDL_PollEvent(&e);

SDL_RenderCopy(renderer, b, NULL, NULL);

SDL_RenderPresent(renderer);
}
return 0;
}
sgrsgsrg
2016-09-23 15:13:12 UTC
Permalink
Got rid of the problem by regenerating all target textures on window resize.

Is there a way to avoid doing that ? This 'glitch' isnt documented anywhere, and there is no fun handling that
Jonathan Dearborn
2016-09-23 15:34:02 UTC
Permalink
Does this happen when you request the OpenGL backend?

Jonny D
Post by sgrsgsrg
Got rid of the problem by regenerating all target textures on window resize.
Is there a way to avoid doing that ? This 'glitch' isnt documented
anywhere, and there is no fun handling that
_______________________________________________
SDL mailing list
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Travis McKinney
2016-09-23 18:50:17 UTC
Permalink
$ sdl2-config --version
2.0.4

Code works as expected on my system. Textures do not swap.
Post by Jonathan Dearborn
Does this happen when you request the OpenGL backend?
Jonny D
Post by sgrsgsrg
Got rid of the problem by regenerating all target textures on window resize.
Is there a way to avoid doing that ? This 'glitch' isnt documented
anywhere, and there is no fun handling that
_______________________________________________
SDL mailing list
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
_______________________________________________
SDL mailing list
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Eric Wing
2016-09-23 22:42:05 UTC
Permalink
Post by sgrsgsrg
Got rid of the problem by regenerating all target textures on window resize.
Is there a way to avoid doing that ? This 'glitch' isnt documented anywhere,
and there is no fun handling that
You didn't say anything about what operating system and video card you
are using, nor which renderer backend. I'll speculate that you are on
Windows and by default, you use the Direct3D backend which is very
susceptible to losing your textures on various window events. (OpenGL
tends to be a little more resilient in my experience.)

Unfortunately, you must handle this. However, this is documented and
there are two SDL events you should look for.

SDL_RENDER_TARGETS_RESET and SDL_RENDER_DEVICE_RESET. When these
events occur, this is when you should reload your textures.

https://wiki.libsdl.org/SDL_EventType


-Eric

Loading...