[vlc-devel] [PATCH] wgl: fix failing wglMakeCurrent

Alexandre Janniaux ajanni at videolabs.io
Sun Apr 4 10:00:04 UTC 2021


Hi,

Sorry, after re-reading, the patch lack some comments about
the actual failure, and documented behaviour from wgl apis,
so I´ll send a better version later.

Regards,
--
Alexandre Janniaux
Videolabs
On Sat, Apr 03, 2021 at 08:13:52PM +0200, Alexandre Janniaux wrote:
> wglMakeCurrent on close() is called from a different thread than other
> functions, thus the DC handle was not valid for the closing thread,
> leading to spurrious 2004 errors or invalid handle errors, leading then
> to OpenGL call failures because no context is current when destroying
> the ressources in the display.
>
> Since this was happening on Close(), there was no way to make it fail
> gracefully so get a new DC on the closing thread instead to fix the
> error.
> ---
>  modules/video_output/win32/wgl.c | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/modules/video_output/win32/wgl.c b/modules/video_output/win32/wgl.c
> index 1f87fb073c..2e9d5a839d 100644
> --- a/modules/video_output/win32/wgl.c
> +++ b/modules/video_output/win32/wgl.c
> @@ -272,12 +272,22 @@ static void *OurGetProcAddress(vlc_gl_t *gl, const char *name)
>  static int MakeCurrent(vlc_gl_t *gl)
>  {
>      vout_display_sys_t *sys = gl->sys;
> -    bool success = wglMakeCurrent(sys->hGLDC, sys->hGLRC);
> -    return success ? VLC_SUCCESS : VLC_EGENERIC;
> +
> +    /* After painting with a common DC, the ReleaseDC function must be called
> +     * to release the DC. Class and private DCs do not have to be released.
> +     * ReleaseDC must be called from the same thread that called GetDC. The
> +     * number of DCs is limited only by available memory. */
> +
> +    HDC winDC = GetDC(sys->hvideownd);
> +    bool success = wglMakeCurrent(winDC, sys->hGLRC);
> +    /* vlc_gl_MakeCurrent should never fail. */
> +    assert(success);
> +    ReleaseDC(sys->hvideownd, winDC);
> +    return VLC_SUCCESS;
>  }
>
>  static void ReleaseCurrent(vlc_gl_t *gl)
>  {
>      vout_display_sys_t *sys = gl->sys;
> -    wglMakeCurrent (sys->hGLDC, NULL);
> +    wglMakeCurrent(NULL, NULL);
>  }
> --
> 2.30.2
>


More information about the vlc-devel mailing list