From c06f4eb7f7ca6ca698e7be74266eac89c3352a11 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 29 Aug 2011 11:10:17 -0700 Subject: Hold a reference on the global context --- Alc/ALc.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'Alc') diff --git a/Alc/ALc.c b/Alc/ALc.c index e9c6000e..9929ee3b 100644 --- a/Alc/ALc.c +++ b/Alc/ALc.c @@ -1337,11 +1337,6 @@ static ALvoid InitContext(ALCcontext *pContext) */ static ALCvoid FreeContext(ALCcontext *context) { - LockLists(); - if(context == GlobalContext) - GlobalContext = NULL; - UnlockLists(); - if(context->SourceMap.size > 0) { ERR("FreeContext(%p): deleting %d Source(s)\n", context, context->SourceMap.size); @@ -2119,6 +2114,12 @@ ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context) ALCdevice_StopPlayback(Device); Device->Flags &= ~DEVICE_RUNNING; } + + if(GlobalContext == context) + { + GlobalContext = NULL; + ALCcontext_DecRef(context); + } UnlockLists(); ALCcontext_DecRef(context); @@ -2192,11 +2193,15 @@ ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context) // context must be a valid Context or NULL if(context == NULL || IsContext(context)) { + ALCcontext *old = GlobalContext; + if(context) ALCcontext_IncRef(context); GlobalContext = context; - if((context=pthread_getspecific(LocalContext)) != NULL) + if(old) ALCcontext_DecRef(old); + + if((old=pthread_getspecific(LocalContext)) != NULL) { pthread_setspecific(LocalContext, NULL); - ALCcontext_DecRef(context); + ALCcontext_DecRef(old); } } else -- cgit v1.2.3