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 4199 - EGL backend changes the current context behind app's back
Summary: EGL backend changes the current context behind app's back
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 2.1
Hardware: x86_64 Linux
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-06-14 06:12 UTC by Tomeu Vizoso
Modified: 2018-06-25 05:48 UTC (History)
1 user (show)

See Also:


Attachments
fix (947 bytes, patch)
2018-06-14 06:12 UTC, Tomeu Vizoso
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tomeu Vizoso 2018-06-14 06:12:12 UTC
Created attachment 3261 [details]
fix

SDL_EGL_DeleteContext calls SDL_EGL_MakeCurrent(_this, NULL, NULL); right before calling eglDestroyContext.

If the context to be destroyed isn't the current one, any context tracking that the app is doing will be broken.

If the context to be destroyed is the current one, SDL_GL_DeleteContext will have unset it already.

This patch brings the behavior of the EGL backend in line with the one in the GLX one.
Comment 1 Sam Lantinga 2018-06-15 03:36:22 UTC
The context needs to no longer be current:
If the EGL rendering context context is not current to any thread, eglDestroyContext destroys it immediately. Otherwise, context is destroyed when it becomes not current to any thread.

The GLX code does the same thing:
        _this->gl_data->glXMakeCurrent(display, None, NULL);
        _this->gl_data->glXDestroyContext(display, context);

If there's a way to tell whether the context is current, that would be the right thing to do.
Comment 2 Tomeu Vizoso 2018-06-15 04:53:16 UTC
(In reply to Sam Lantinga from comment #1)
> The context needs to no longer be current:
> If the EGL rendering context context is not current to any thread,
> eglDestroyContext destroys it immediately. Otherwise, context is destroyed
> when it becomes not current to any thread.
> 
> The GLX code does the same thing:
>         _this->gl_data->glXMakeCurrent(display, None, NULL);
>         _this->gl_data->glXDestroyContext(display, context);

I see that in X11_GL_InitExtensions, but not in X11_GL_DeleteContext.

> If there's a way to tell whether the context is current, that would be the
> right thing to do.

SDL_GL_DeleteContext already takes care of that:

    if (SDL_GL_GetCurrentContext() == context) {
        SDL_GL_MakeCurrent(NULL, NULL);
    }

    _this->GL_DeleteContext(_this, context);
Comment 3 Ryan C. Gordon 2018-06-25 05:48:39 UTC
Tomeu is right, this patch is now https://hg.libsdl.org/SDL/rev/8aa5a79c8805

Thanks!

--ryan.