diff options
author | Chris Robinson <[email protected]> | 2011-08-29 11:10:17 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2011-08-29 11:10:17 -0700 |
commit | c06f4eb7f7ca6ca698e7be74266eac89c3352a11 (patch) | |
tree | 04fe170b5f7578c1c0a7562df18ac0855157b7ac /Alc/ALc.c | |
parent | 0abe13e3adfea3e8181bd89064331fe2640c969c (diff) |
Hold a reference on the global context
Diffstat (limited to 'Alc/ALc.c')
-rw-r--r-- | Alc/ALc.c | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -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 |