SDL from .Net C++ WinForms - threading issue

I have been working on building a video player object that I can embed into a .Net application.
The intent is for a component that I can drop on a C# form.
Currently using a .Net C++ (managed) dll to call a native C++ class that interfaces to SDL and FFMPEG.

I am passing in a handle of a windows forms panel into the .Net DLL class and using SetWindowPos() and SetParent() to get the SDL window in the correct location.

Things were working well, but I had the decoding/rendering loop launched from a form button, which meant it was on the GUI thread.
I then moved the decoding/rendering code into its own thread, and ran into some issues.

I can move the window around the screen and the video keeps playing, but the moment I try to resize the video frame, the video stops playing.
The last frame displayed will resize as the window is resized, but no more video updates.

Interesting thing is, if I put break points in the decoding/rendering thread, it is still chugging away and runs until it reaches the end of the video file.

I believe this is some sort of cross-thread conflict, but I’m stumped as to what the cause might be.

Any ideas would be greatly appreciated!

Thanks
-Al

So over 1000 views, yet not one suggestion…

Seems this has something to do with how SDL implements its threads.
I am guessing that by I creating an instance of a window/renderer in one thread, and try to then use (update) in another thread, the bug rears its head.

No offense to the developers of SDL, but it seems that SDL is not the right tool for the job…

I have the same problem.
I saw this article while searching some solution.

Sorry, I’m not good at English.

I think this is not a threading issue.
The logic of ffplay is recretae texture when window is resized.
I think winform and native window is somthing different.
So I will recreate all of the window, renderer and texture after resize window.
I will recomment after test it.

=== after test (almost Successful) ===

I modified the logic menthioned above, and test it.
Video still updating after resize window ^^

The only thing I’m worrying is that I could’nt call SDL_DestroyWindow before recreate window.
Because when call SDL_DestroyWindow, the window will close.

======================================

//save Handle is winform handle
const void *saveHandle = NULL;
static void resetWindow(VideoState *cur_stream)
{
int ok = 0;

if (saveHandle) window = SDL_CreateWindowFrom(saveHandle);

if (window) {
	int w = 0, h = 0;
	SDL_GetWindowSize(window, &w, &h);
	printf("%d,%d\n", w, h);
	if (w > 0 && h > 0)
	{
		if (renderer) SDL_DestroyRenderer(renderer);
		renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
		if (renderer) {
			screen_width = cur_stream->width = w;
			screen_height = cur_stream->height = h;
			if (cur_stream->vis_texture) {
				SDL_DestroyTexture(cur_stream->vis_texture);
				cur_stream->vis_texture = NULL;
			}
			ok = 1;
		}
	}
}

if (!ok) bexit = 1;

}

//event loop

	case SDL_WINDOWEVENT:
		switch (event.window.event) {
		case SDL_WINDOWEVENT_RESIZED:
			//screen_width = cur_stream->width = event.window.data1;
			//screen_height = cur_stream->height = event.window.data2;
			//if (cur_stream->vis_texture) {
			//	SDL_DestroyTexture(cur_stream->vis_texture);
			//	cur_stream->vis_texture = NULL;
			//}
			resetWindow(cur_stream);
		case SDL_WINDOWEVENT_EXPOSED:
			cur_stream->force_refresh = 1;
		}
		break;