We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2746

Summary: Render dies after SDL_SetWindowSize in other thread
Product: SDL Reporter: alexander <aiac0692>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: critical    
Priority: P2 CC: amaranth72
Version: 2.0.3   
Hardware: x86_64   
OS: Windows 7   

Description alexander 2014-10-07 11:13:55 UTC
Good afternoon.
I use the following code and I receive an error.

   SDL_Window * WindowTest;   
   SDL_Renderer * RenderTest;   
   SDL_Texture * TextureTest;

   void FirstThread()
   {
	WindowTest= SDL_CreateWindow(0,
					0,
					0,
					640,480,
				SDL_WINDOW_SHOWN|
                                SDL_WINDOW_FOREIGN|
                                SDL_WINDOW_BORDERLESS);
	RenderTest = SDL_CreateRenderer(WindowTest,-1,SDL_RENDERER_ACCELERATED);
	TextureTest = SDL_CreateTexture(RenderTest,
					SDL_PIXELFORMAT_IYUV,
					SDL_TEXTUREACCESS_STREAMING,
					640,480);
	SDL_SetWindowSize(WindowTest,600,400);
	if(SDL_RenderClear(RenderTest)!=0)
	{
		printf("SDL_RenderClear failed: %s\n", SDL_GetError());
		fflush(0);
	}
	// All OK!!!
	SDL_DestroyTexture(TextureTest);
	TextureTest = SDL_CreateTexture(RenderTest,
		SDL_PIXELFORMAT_IYUV,
		SDL_TEXTUREACCESS_STREAMING,
		600,400);
   }
   void SecondThread()
   {
	SDL_SetWindowSize(WindowTest,500,300);
	if(SDL_RenderClear(RenderTest)!=0)
	{
		printf("SDL_RenderClear failed: %s\n", SDL_GetError());
		fflush(0);
	}
	// ERROR!!!! INVALIDCALL!!
   }

   int main ()
   {
        boost::thread * first=new boost::thread(&FirstThread);
	first->join();
	boost::thread * second=new boost::thread(&SecondThread);
	second->join();
   }

In other thread I can't change the size. I tried the SDL 2.0.3 version.
Also I tried the version which is specified in "BUG" 1676. It doesn't work.
https://bugzilla.libsdl.org/show_bug.cgi? id=1676
Help please...
Comment 1 Alex Szpakowski 2014-10-07 21:03:24 UTC
SDL_Render must only be used in the main thread. This isn't a bug with SDL, just limitations of the underlying GPU APIs. A comment at the top of the SDL_render.h file mentions this as well.

Similarly, I believe most of the window-related functions are not designed to be used in multiple threads either.
Comment 2 alexander 2014-10-08 06:52:55 UTC
It's OK, thanks.
How I shall use Render if I host events from a mouse (SDL_MOUSEBUTTONDOWN) in other thread? To increase a window on mouse click... I shall create main thread and host events for processing of Render?
Comment 3 Sam Lantinga 2017-08-14 04:59:35 UTC
Yes, that's the typical approach.

Cheers,