Renderer freeze when lock screen and login again

I’m using SDL-2.0.4 for rndering YUV frame, the program works fine except when lock the screen (Win+L) and login again.

The renderer type is direct3d, I guess when locking screen, the D3D device lost.

I’m trying to handle SDL_RENDER_DEVICE_RESET event, but it never triggered.

Sample codes:


// Create window, renderer and texture
m_sdl_window = SDL_CreateWindow("RTMP Player",
                                m_output_width, m_output_height,
m_sdl_renderer = SDL_CreateRenderer(m_sdl_window, -1, 0);
m_sdl_texture = SDL_CreateTexture(m_sdl_renderer,

// Display yuv frame
do {
    m_output_frame = try_to_get_a_frame(...)

    // Update texture
    ret = SDL_UpdateYUVTexture(m_sdl_texture, &m_sdl_rect,
                               m_output_frame->data[0], m_output_frame->linesize[0],
                               m_output_frame->data[1], m_output_frame->linesize[1],
                               m_output_frame->data[2], m_output_frame->linesize[2]);
    if (0 != ret) {
        _error("SDL_UpdateYUVTexture failed! - err: %d", ret);

    ret = SDL_RenderClear(m_sdl_renderer);
    if (0 != ret) {
        _error("SDL_RenderClear failed! - err: %d", ret);

    ret = SDL_RenderCopy(m_sdl_renderer, m_sdl_texture, NULL, &m_sdl_rect);
    if (0 != ret) {
        _error("SDL_RenderCopy failed! - err: %d", ret);

} while (1);

The same problem here. The program stops rendering when Windows UAC blanks the screen and aks if I really want to blah blah… After this the program no longer works.

The workaround was to do this when SDL_WINDOWEVENT_ENTER


SDL_DestroyTexture( sdlTexture );
SDL_DestroyRenderer( sdlRenderer );
sdlRenderer := SDL_CreateRenderer(scr, -1, 0);
sdlTexture := SDL_CreateTexture(sdlRenderer,SDL_PIXELFORMAT_ARGB8888,SDL_TEXTUREACCESS_STreaming,1792,1120);

Now it works but sometimes crashes with segmentation fault. The SDL_RENDER_DEVICE_RESET is never triggered.

I lowered UAC settings, so the screen doesn’t go dim anymore, but this is not a solution.

When the SDL_RENDER_DEVICE_RESET is triggered? How to use it? How to avoid situation described above?

My code stopped crashing when I moved all SDL graphics calls to one thread and one main loop. So my problem is solved (but I still don’t know how to use SDL_RENDER_DEVICE_RESET and when it is triggered).