From 84a90b7cc39a797781566ceebd6de40c495808aa Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 20 Sep 2018 22:44:58 -0700 Subject: Stop the event thread when releasing the context To ensure no user callback gets called after alcDestroyContext. --- Alc/ALc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Alc') diff --git a/Alc/ALc.c b/Alc/ALc.c index 57ae4ace..7d3e3649 100644 --- a/Alc/ALc.c +++ b/Alc/ALc.c @@ -2680,7 +2680,6 @@ static ALvoid InitContext(ALCcontext *Context) */ static void FreeContext(ALCcontext *context) { - static const AsyncEvent kill_evt = ASYNC_EVENT(EventType_KillThread); ALlistener *listener = context->Listener; struct ALeffectslotArray *auxslots; struct ALeffectslotProps *eprops; @@ -2692,11 +2691,6 @@ static void FreeContext(ALCcontext *context) TRACE("%p\n", context); - while(ll_ringbuffer_write(context->AsyncEvents, (const char*)&kill_evt, 1) == 0) - althrd_yield(); - alsem_post(&context->EventSem); - althrd_join(context->EventThread, NULL); - if((cprops=ATOMIC_LOAD(&context->Update, almemory_order_acquire)) != NULL) { TRACE("Freed unapplied context update %p\n", cprops); @@ -2809,6 +2803,7 @@ static void FreeContext(ALCcontext *context) */ static bool ReleaseContext(ALCcontext *context, ALCdevice *device) { + static const AsyncEvent kill_evt = ASYNC_EVENT(EventType_KillThread); ALCcontext *origctx, *newhead; bool ret = true; @@ -2841,6 +2836,11 @@ static bool ReleaseContext(ALCcontext *context, ALCdevice *device) ret = !!newhead; V0(device->Backend,unlock)(); + while(ll_ringbuffer_write(context->AsyncEvents, (const char*)&kill_evt, 1) == 0) + althrd_yield(); + alsem_post(&context->EventSem); + althrd_join(context->EventThread, NULL); + ALCcontext_DecRef(context); return ret; } -- cgit v1.2.3