Skip to content

Commit

Permalink
alcDestroyContext() forbids destruction of the current context.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Apr 17, 2018
1 parent 8ffe047 commit 6c3644d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions mojoal.c
Expand Up @@ -1156,10 +1156,22 @@ void alcSuspendContext(ALCcontext *context)
SDL_AtomicSet(&context->processing, 0);
}

static inline ALCcontext *get_current_context(void)
{
return (ALCcontext *) SDL_AtomicGetPtr(&current_context);
}

void alcDestroyContext(ALCcontext *context)
{
FIXME("Should NULL context be an error?");
if (!context) return;

/* The spec says it's illegal to delete the current context. */
if (get_current_context() == context) {
set_alc_error(context->device, ALC_INVALID_CONTEXT);
return;
}

/* do this first in case the mixer is running _right now_. */
SDL_AtomicSet(&context->processing, 0);

Expand All @@ -1176,11 +1188,6 @@ void alcDestroyContext(ALCcontext *context)
SDL_UnlockAudioDevice(context->device->sdldevice);
}

static inline ALCcontext *get_current_context(void)
{
return (ALCcontext *) SDL_AtomicGetPtr(&current_context);
}

ALCcontext *alcGetCurrentContext(void)
{
return get_current_context();
Expand Down

0 comments on commit 6c3644d

Please sign in to comment.