Created attachment 93443 [details]
Example that exhibits the issue
Releasing a surfaceless EGL context doesn't properly release the underlying DRI context, sometimes leading to crashes. I have attached an example that exhibits such a crash (run it in a VT).
Without a fix, the example crashes when the main thread tries to make context2 current, because mesa tries to _mesa_flush the invalid (destroyed in the other thread) context1, left as current in the main thread by the previous make current operation (and not cleaned by releasing the egl context).
The problem seems to be that the driUnbindContext() function doesn't call the driver unbind function if the context is surfaceless. Moving the call to the driver function before the drawable validity checks fixes things for me (see attached patch), although I am not familiar enough with that code to be confident that this is indeed the right approach.
Note the absence of _mesa_make_current() calls for context releases in the logs:
# MESA_VERBOSE=api ./mesa_surfaceless_context_crash
T1: Make current 1
T1: Release current 1
T1: after Release current 1
Main: Make current 1
Main: Release current 1
Main: after Release current 1
Mesa: glDeleteTextures 1
Main: Make current 2
I am using latest Mesa git with the i965 driver.
Created attachment 93444 [details] [review]
Can you send the patch for review to Mesa mailing list?
was pushed to master
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct.