SDL_CreateWindowFrom Vs SDL_CreateWindow - Resize Window on Windowz

Hi, I’m sure to be missing something obvious here, however… long story short, using the simple sample at the following URL:

Change it to using our own HWND (SDL_CreateWindowFrom )

The app crash’s on resize, whether the renderer is software or accelerated(dx9), access violation…
Any pointers appreciated, using the latest 2.0.8 SDL2.
Cheers!

Hello,

I’m still having basic issues when providing my own HWND and get the similar results for:
SDL_RENDERER_SOFTWARE = Access Violation Exception thrown at 0x000000006C7F7447 (SDL2.dll)
SDL_RENDERER_ACCELERATED = SDL_RenderClear returns “Reset(): INVALIDCALL”
or 0 in SDL_CreateRenderer

I have even tried to reset the renderer, texture and window on a change of window size with reset calls to SDL_CreateWindowFrom, SDL_CreateRenderer, SDL_CreateTexture, no joy…
Tried locking the surface, tried calling SDL_RenderSetViewport, SDL_RenderSetLogicalSize…

Everything works fine in a steady state from the first time I open the window, no matter what odd size.
Is this a bug in SDL2?
It must be common to create a YUV texture and renderer it using your own HWND?

code (simplified):
m_pSDLWindow = SDL_CreateWindowFrom(m_HWnd);
m_pSDLRenderer = SDL_CreateRenderer(m_pSDLWindow, -1, 0);// SDL_RENDERER_SOFTWARE);
m_pSDLTexture = SDL_CreateTexture(m_pSDLRenderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING, m_pCodecCtx->width, m_pCodecCtx->height);

avError = avcodec_decode_video2(m_pCodecCtx, m_pFrame, &frameFinished, pPacket);
sws_scale(m_pSws_ctx, (uint8_t const * const *)m_pFrame->data,
m_pFrame->linesize, 0, m_pCodecCtx->height,
m_pFrameYUV->data, m_pFrameYUV->linesize);
drawError = SDL_UpdateYUVTexture(m_pSDLTexture, &r, m_pFrameYUV->data[0],
m_pFrameYUV->linesize[0], m_pFrameYUV->data[1], m_pFrameYUV->linesize[1],
m_pFrameYUV->data[2], m_pFrameYUV->linesize[2]);

drawError = SDL_RenderClear(m_pSDLRenderer);
drawError = SDL_RenderCopy(m_pSDLRenderer, m_pSDLTexture, NULL, NULL);

SDL_RenderPresent(m_pSDLRenderer);

I would like to add that after 3 days of applying hacks around SDL (WM_SIZE hooks) I have given up.

Unfortunately the software is unstable when providing your own window handle and sizing a window.

Its probably for the best that you do not advertise this functionality as it’s a waste of dev time…

Let me know if you require any help to reproduce access violations in either accelerated or software modes, you can do it in a few lines of code.

The SDL docs say that (in Microsoft Windows) “the hint SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT needs to be configured before using SDL_CreateWindowFrom()” but I don’t see this in your code. It’s not clear how you are supposed to use it however (since it takes the address of another SDL window).

Cheers for the input Russell, I think this is for OpenGL only, I gave it a go for both SDL_RENDERER_SOFTWARE & SDL_RENDERER_ACCELERATED anyway with no joy, followed the examples on the web as I’m unsure how you can call the hint with the created window handle before the call to create window handle :)!

I’m going for good old fashion StretchBlt now which is bad performance, but will always work.

The wording in the docs is “In some cases (e.g. OpenGL) and on some platforms (e.g. Microsoft Windows)” which is ambiguous. It could be interpreted as meaning you always need to use the hint in Windows, but as written it’s impossible to know.

Should I create a bug using https://bugzilla.libsdl.org/ ?
Cheers

I solve the problem by the SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT micro.and choose the opengl render driver,otherwise, you will get a crash when resize the window frequently.