Jump to content
  • Advertisement
Sign in to follow this  

SDL2 : Target textures getting randomly swapped on window resize ?

This topic is 824 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Having a strange random texture swap in my game, i had to investigate oh this, and i fear i found a huge bug in SDL2.


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 !!! I never ask to draw A !! icon_eek.gif 
You can have even 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 each time you resize the window.
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 and so on... 

WTF is happening rly... do you have the same problem ? am I doing something wrong ? 

#include <SDL.h>

int main(){
	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_RenderCopy(renderer, b, NULL, NULL);

	return 0;
Edited by isbinil

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!