Allocate context storage before starting/resetting the device

In case allocation fails, we don't have to worry about the playing status of
the backend.
This commit is contained in:
Chris Robinson
2016-05-15 14:12:56 -07:00
parent c522658d19
commit 63e98481ee
+23 -19
View File
@@ -3078,20 +3078,6 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin
ATOMIC_STORE(&device->LastError, ALC_NO_ERROR);
if((err=UpdateDeviceParams(device, attrList)) != ALC_NO_ERROR)
{
UnlockLists();
alcSetError(device, err);
if(err == ALC_INVALID_DEVICE)
{
V0(device->Backend,lock)();
aluHandleDisconnect(device);
V0(device->Backend,unlock)();
}
ALCdevice_DecRef(device);
return NULL;
}
ALContext = al_calloc(16, sizeof(ALCcontext)+sizeof(ALlistener));
if(ALContext)
{
@@ -3106,11 +3092,6 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin
}
if(!ALContext || !ALContext->Voices)
{
if(!ATOMIC_LOAD(&device->ContextList))
{
V0(device->Backend,stop)();
device->Flags &= ~DEVICE_RUNNING;
}
UnlockLists();
if(ALContext)
@@ -3129,6 +3110,29 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin
return NULL;
}
if((err=UpdateDeviceParams(device, attrList)) != ALC_NO_ERROR)
{
UnlockLists();
al_free(ALContext->Voices);
ALContext->Voices = NULL;
VECTOR_DEINIT(ALContext->ActiveAuxSlots);
al_free(ALContext);
ALContext = NULL;
alcSetError(device, err);
if(err == ALC_INVALID_DEVICE)
{
V0(device->Backend,lock)();
aluHandleDisconnect(device);
V0(device->Backend,unlock)();
}
ALCdevice_DecRef(device);
return NULL;
}
ALContext->Device = device;
ALCdevice_IncRef(device);
InitContext(ALContext);