From: Gregory Hainaut <gregory.hain...@gmail.com>

Fix crashes when glxMakeCurrent is called.

Signed-off-by: Gregory Hainaut <gregory.hain...@gmail.com>
Signed-off-by: Marek Olšák <marek.ol...@amd.com>
---
 src/mesa/main/glthread.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/mesa/main/glthread.c b/src/mesa/main/glthread.c
index 8f300d4..8ee7d8d 100644
--- a/src/mesa/main/glthread.c
+++ b/src/mesa/main/glthread.c
@@ -166,23 +166,30 @@ _mesa_glthread_destroy(struct gl_context *ctx)
     * point, and no batches queued.
     */
    assert(!glthread->batch->used);
    assert(!glthread->batch->next);
    free(glthread->batch);
    assert(!glthread->batch_queue);
 
    free(glthread);
    ctx->GLThread = NULL;
 
-   /* Remove ourselves from the dispatch table. */
-   ctx->CurrentClientDispatch = ctx->CurrentServerDispatch;
-   _glapi_set_dispatch(ctx->CurrentClientDispatch);
+   /* Remove ourselves from the dispatch table except if another ctx/thread
+    * already installed a new dispatch table.
+    *
+    * Typically glxMakeCurrent will bind a new context (install new table) then
+    * old context might be deleted.
+    */
+   if (_glapi_get_dispatch() == ctx->MarshalExec) {
+       ctx->CurrentClientDispatch = ctx->CurrentServerDispatch;
+       _glapi_set_dispatch(ctx->CurrentClientDispatch);
+   }
 }
 
 void
 _mesa_glthread_flush_batch(struct gl_context *ctx)
 {
    struct glthread_state *glthread = ctx->GLThread;
    struct glthread_batch *batch;
 
    if (!glthread)
       return;
-- 
2.9.3

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to