diff options
author | Chris Robinson <[email protected]> | 2009-12-28 23:19:13 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2009-12-28 23:19:13 -0800 |
commit | 7ee81eac0fd1ecd719c906cfc8fc9a81fcf0ffbe (patch) | |
tree | a3b955467e7d67e7369d6f38b23910cffdbac367 /Alc/ALc.c | |
parent | c9a08fc7b235425058d3e28ddc46ae56dc726d7d (diff) |
Store ALC errors with the device when possible
Diffstat (limited to 'Alc/ALc.c')
-rw-r--r-- | Alc/ALc.c | 131 |
1 files changed, 65 insertions, 66 deletions
@@ -508,9 +508,12 @@ static ALCboolean IsContext(ALCcontext *pContext) Store latest ALC Error */ -ALCvoid alcSetError(ALenum errorCode) +ALCvoid alcSetError(ALCdevice *device, ALenum errorCode) { - g_eLastContextError = errorCode; + if(IsDevice(device)) + device->LastError = errorCode; + else + g_eLastContextError = errorCode; } @@ -637,7 +640,7 @@ ALCAPI ALCdevice* ALCAPIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, AL if(SampleSize <= 0) { - alcSetError(ALC_INVALID_VALUE); + alcSetError(NULL, ALC_INVALID_VALUE); return NULL; } @@ -679,13 +682,13 @@ ALCAPI ALCdevice* ALCAPIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, AL if(!DeviceFound) { - alcSetError(ALC_INVALID_VALUE); + alcSetError(NULL, ALC_INVALID_VALUE); free(pDevice); pDevice = NULL; } } else - alcSetError(ALC_OUT_OF_MEMORY); + alcSetError(NULL, ALC_OUT_OF_MEMORY); return pDevice; } @@ -718,7 +721,7 @@ ALCAPI ALCboolean ALCAPIENTRY alcCaptureCloseDevice(ALCdevice *pDevice) bReturn = ALC_TRUE; } else - alcSetError(ALC_INVALID_DEVICE); + alcSetError(pDevice, ALC_INVALID_DEVICE); return bReturn; } @@ -728,7 +731,7 @@ ALCAPI void ALCAPIENTRY alcCaptureStart(ALCdevice *pDevice) if(IsDevice(pDevice) && pDevice->IsCaptureDevice) ALCdevice_StartCapture(pDevice); else - alcSetError(ALC_INVALID_DEVICE); + alcSetError(pDevice, ALC_INVALID_DEVICE); } ALCAPI void ALCAPIENTRY alcCaptureStop(ALCdevice *pDevice) @@ -736,7 +739,7 @@ ALCAPI void ALCAPIENTRY alcCaptureStop(ALCdevice *pDevice) if(IsDevice(pDevice) && pDevice->IsCaptureDevice) ALCdevice_StopCapture(pDevice); else - alcSetError(ALC_INVALID_DEVICE); + alcSetError(pDevice, ALC_INVALID_DEVICE); } ALCAPI void ALCAPIENTRY alcCaptureSamples(ALCdevice *pDevice, ALCvoid *pBuffer, ALCsizei lSamples) @@ -744,7 +747,7 @@ ALCAPI void ALCAPIENTRY alcCaptureSamples(ALCdevice *pDevice, ALCvoid *pBuffer, if(IsDevice(pDevice) && pDevice->IsCaptureDevice) ALCdevice_CaptureSamples(pDevice, pBuffer, lSamples); else - alcSetError(ALC_INVALID_DEVICE); + alcSetError(pDevice, ALC_INVALID_DEVICE); } /* @@ -754,12 +757,13 @@ ALCAPI void ALCAPIENTRY alcCaptureSamples(ALCdevice *pDevice, ALCvoid *pBuffer, */ ALCAPI ALCenum ALCAPIENTRY alcGetError(ALCdevice *device) { - ALCenum errorCode; - - (void)device; + ALCenum errorCode = ALC_NO_ERROR; - errorCode = g_eLastContextError; - g_eLastContextError = ALC_NO_ERROR; + if(device) + { + errorCode = device->LastError; + device->LastError = ALC_NO_ERROR; + } return errorCode; } @@ -857,7 +861,7 @@ ALCAPI const ALCchar* ALCAPIENTRY alcGetString(ALCdevice *pDevice,ALCenum param) free(alcDefaultDeviceSpecifier); alcDefaultDeviceSpecifier = strdup(alcDeviceList ? alcDeviceList : ""); if(!alcDefaultDeviceSpecifier) - alcSetError(ALC_OUT_OF_MEMORY); + alcSetError(pDevice, ALC_OUT_OF_MEMORY); value = alcDefaultDeviceSpecifier; break; @@ -866,7 +870,7 @@ ALCAPI const ALCchar* ALCAPIENTRY alcGetString(ALCdevice *pDevice,ALCenum param) alcDefaultAllDeviceSpecifier = strdup(alcAllDeviceList ? alcAllDeviceList : ""); if(!alcDefaultAllDeviceSpecifier) - alcSetError(ALC_OUT_OF_MEMORY); + alcSetError(pDevice, ALC_OUT_OF_MEMORY); value = alcDefaultAllDeviceSpecifier; break; @@ -875,7 +879,7 @@ ALCAPI const ALCchar* ALCAPIENTRY alcGetString(ALCdevice *pDevice,ALCenum param) alcCaptureDefaultDeviceSpecifier = strdup(alcCaptureDeviceList ? alcCaptureDeviceList : ""); if(!alcCaptureDefaultDeviceSpecifier) - alcSetError(ALC_OUT_OF_MEMORY); + alcSetError(pDevice, ALC_OUT_OF_MEMORY); value = alcCaptureDefaultDeviceSpecifier; break; @@ -884,7 +888,7 @@ ALCAPI const ALCchar* ALCAPIENTRY alcGetString(ALCdevice *pDevice,ALCenum param) break; default: - alcSetError(ALC_INVALID_ENUM); + alcSetError(pDevice, ALC_INVALID_ENUM); break; } @@ -910,18 +914,18 @@ ALCAPI ALCvoid ALCAPIENTRY alcGetIntegerv(ALCdevice *device,ALCenum param,ALsize if ((size) && (data)) *data = ALCdevice_AvailableSamples(device); else - alcSetError(ALC_INVALID_VALUE); + alcSetError(device, ALC_INVALID_VALUE); break; case ALC_CONNECTED: if(size <= 0) - alcSetError(ALC_INVALID_VALUE); + alcSetError(device, ALC_INVALID_VALUE); else *data = device->Connected; break; default: - alcSetError(ALC_INVALID_ENUM); + alcSetError(device, ALC_INVALID_ENUM); break; } @@ -936,53 +940,53 @@ ALCAPI ALCvoid ALCAPIENTRY alcGetIntegerv(ALCdevice *device,ALCenum param,ALsize { case ALC_MAJOR_VERSION: if(size <= 0) - alcSetError(ALC_INVALID_VALUE); + alcSetError(device, ALC_INVALID_VALUE); else *data = alcMajorVersion; break; case ALC_MINOR_VERSION: if(size <= 0) - alcSetError(ALC_INVALID_VALUE); + alcSetError(device, ALC_INVALID_VALUE); else *data = alcMinorVersion; break; case ALC_EFX_MAJOR_VERSION: if(size <= 0) - alcSetError(ALC_INVALID_VALUE); + alcSetError(device, ALC_INVALID_VALUE); else *data = alcEFXMajorVersion; break; case ALC_EFX_MINOR_VERSION: if(size <= 0) - alcSetError(ALC_INVALID_VALUE); + alcSetError(device, ALC_INVALID_VALUE); else *data = alcEFXMinorVersion; break; case ALC_MAX_AUXILIARY_SENDS: if(size <= 0) - alcSetError(ALC_INVALID_VALUE); + alcSetError(device, ALC_INVALID_VALUE); else *data = (device?device->NumAuxSends:MAX_SENDS); break; case ALC_ATTRIBUTES_SIZE: if(!IsDevice(device)) - alcSetError(ALC_INVALID_DEVICE); + alcSetError(device, ALC_INVALID_DEVICE); else if(size <= 0) - alcSetError(ALC_INVALID_VALUE); + alcSetError(device, ALC_INVALID_VALUE); else *data = 13; break; case ALC_ALL_ATTRIBUTES: if(!IsDevice(device)) - alcSetError(ALC_INVALID_DEVICE); + alcSetError(device, ALC_INVALID_DEVICE); else if (size < 13) - alcSetError(ALC_INVALID_VALUE); + alcSetError(device, ALC_INVALID_VALUE); else { int i = 0; @@ -1013,65 +1017,65 @@ ALCAPI ALCvoid ALCAPIENTRY alcGetIntegerv(ALCdevice *device,ALCenum param,ALsize case ALC_FREQUENCY: if(!IsDevice(device)) - alcSetError(ALC_INVALID_DEVICE); + alcSetError(device, ALC_INVALID_DEVICE); else if(size <= 0) - alcSetError(ALC_INVALID_VALUE); + alcSetError(device, ALC_INVALID_VALUE); else *data = device->Frequency; break; case ALC_REFRESH: if(!IsDevice(device)) - alcSetError(ALC_INVALID_DEVICE); + alcSetError(device, ALC_INVALID_DEVICE); else if(size <= 0) - alcSetError(ALC_INVALID_VALUE); + alcSetError(device, ALC_INVALID_VALUE); else *data = device->Frequency / device->UpdateSize; break; case ALC_SYNC: if(!IsDevice(device)) - alcSetError(ALC_INVALID_DEVICE); + alcSetError(device, ALC_INVALID_DEVICE); else if(size <= 0) - alcSetError(ALC_INVALID_VALUE); + alcSetError(device, ALC_INVALID_VALUE); else *data = ALC_FALSE; break; case ALC_MONO_SOURCES: if(!IsDevice(device)) - alcSetError(ALC_INVALID_DEVICE); + alcSetError(device, ALC_INVALID_DEVICE); else if(size <= 0) - alcSetError(ALC_INVALID_VALUE); + alcSetError(device, ALC_INVALID_VALUE); else *data = device->lNumMonoSources; break; case ALC_STEREO_SOURCES: if(!IsDevice(device)) - alcSetError(ALC_INVALID_DEVICE); + alcSetError(device, ALC_INVALID_DEVICE); else if(size <= 0) - alcSetError(ALC_INVALID_VALUE); + alcSetError(device, ALC_INVALID_VALUE); else *data = device->lNumStereoSources; break; case ALC_CONNECTED: if(!IsDevice(device)) - alcSetError(ALC_INVALID_DEVICE); + alcSetError(device, ALC_INVALID_DEVICE); else if(size <= 0) - alcSetError(ALC_INVALID_VALUE); + alcSetError(device, ALC_INVALID_VALUE); else *data = device->Connected; break; default: - alcSetError(ALC_INVALID_ENUM); + alcSetError(device, ALC_INVALID_ENUM); break; } } else if(size) - alcSetError(ALC_INVALID_VALUE); + alcSetError(device, ALC_INVALID_VALUE); } return; @@ -1087,8 +1091,6 @@ ALCAPI ALCboolean ALCAPIENTRY alcIsExtensionPresent(ALCdevice *device, const ALC { ALCboolean bResult = ALC_FALSE; - (void)device; - if (extName) { const char *ptr; @@ -1113,7 +1115,7 @@ ALCAPI ALCboolean ALCAPIENTRY alcIsExtensionPresent(ALCdevice *device, const ALC } } else - alcSetError(ALC_INVALID_VALUE); + alcSetError(device, ALC_INVALID_VALUE); return bResult; } @@ -1129,8 +1131,6 @@ ALCAPI ALCvoid * ALCAPIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar ALCvoid *pFunction = NULL; ALsizei i = 0; - (void)device; - if (funcName) { while(alcFunctions[i].funcName && @@ -1139,7 +1139,7 @@ ALCAPI ALCvoid * ALCAPIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar pFunction = alcFunctions[i].address; } else - alcSetError(ALC_INVALID_VALUE); + alcSetError(device, ALC_INVALID_VALUE); return pFunction; } @@ -1155,14 +1155,12 @@ ALCAPI ALCenum ALCAPIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *enu ALsizei i = 0; ALCenum val; - (void)device; - while ((enumeration[i].enumName)&&(strcmp(enumeration[i].enumName,enumName))) i++; val = enumeration[i].value; if(!enumeration[i].enumName) - alcSetError(ALC_INVALID_VALUE); + alcSetError(device, ALC_INVALID_VALUE); return val; } @@ -1184,13 +1182,13 @@ ALCAPI ALCcontext* ALCAPIENTRY alcCreateContext(ALCdevice *device, const ALCint if(!IsDevice(device) || device->IsCaptureDevice || !device->Connected) { - alcSetError(ALC_INVALID_DEVICE); + alcSetError(device, ALC_INVALID_DEVICE); ProcessContext(NULL); return NULL; } // Reset Context Last Error code - g_eLastContextError = ALC_NO_ERROR; + device->LastError = ALC_NO_ERROR; // If a context is already running on the device, stop playback so the // device attributes can be updated @@ -1251,7 +1249,7 @@ ALCAPI ALCcontext* ALCAPIENTRY alcCreateContext(ALCdevice *device, const ALCint if(ALCdevice_ResetPlayback(device) == ALC_FALSE) { - alcSetError(ALC_INVALID_DEVICE); + alcSetError(device, ALC_INVALID_DEVICE); aluHandleDisconnect(device); ProcessContext(NULL); return NULL; @@ -1271,7 +1269,7 @@ ALCAPI ALCcontext* ALCAPIENTRY alcCreateContext(ALCdevice *device, const ALCint if(ALEffect_DeviceUpdate(slot->EffectState, device) == AL_FALSE) { - alcSetError(ALC_INVALID_DEVICE); + alcSetError(device, ALC_INVALID_DEVICE); aluHandleDisconnect(device); ProcessContext(context); ProcessContext(NULL); @@ -1318,7 +1316,7 @@ ALCAPI ALCcontext* ALCAPIENTRY alcCreateContext(ALCdevice *device, const ALCint temp = realloc(device->Contexts, (device->NumContexts+1) * sizeof(*device->Contexts)); if(!temp) { - alcSetError(ALC_OUT_OF_MEMORY); + alcSetError(device, ALC_OUT_OF_MEMORY); ProcessContext(NULL); return NULL; } @@ -1327,7 +1325,7 @@ ALCAPI ALCcontext* ALCAPIENTRY alcCreateContext(ALCdevice *device, const ALCint ALContext = calloc(1, sizeof(ALCcontext)); if(!ALContext) { - alcSetError(ALC_OUT_OF_MEMORY); + alcSetError(device, ALC_OUT_OF_MEMORY); ProcessContext(NULL); return NULL; } @@ -1414,7 +1412,7 @@ ALCAPI ALCvoid ALCAPIENTRY alcDestroyContext(ALCcontext *context) free(context); } else - alcSetError(ALC_INVALID_CONTEXT); + alcSetError(NULL, ALC_INVALID_CONTEXT); } @@ -1470,7 +1468,7 @@ ALCAPI ALCdevice* ALCAPIENTRY alcGetContextsDevice(ALCcontext *pContext) if (IsContext(pContext)) pDevice = pContext->Device; else - alcSetError(ALC_INVALID_CONTEXT); + alcSetError(NULL, ALC_INVALID_CONTEXT); ProcessContext(NULL); return pDevice; @@ -1509,7 +1507,7 @@ ALCAPI ALCboolean ALCAPIENTRY alcMakeContextCurrent(ALCcontext *context) } else { - alcSetError(ALC_INVALID_CONTEXT); + alcSetError(NULL, ALC_INVALID_CONTEXT); bReturn = AL_FALSE; } @@ -1534,7 +1532,7 @@ ALCboolean ALCAPIENTRY alcMakeCurrent(ALCcontext *context) tls_set(LocalContext, context); else { - alcSetError(ALC_INVALID_CONTEXT); + alcSetError(NULL, ALC_INVALID_CONTEXT); bReturn = AL_FALSE; } @@ -1677,6 +1675,7 @@ ALCAPI ALCdevice* ALCAPIENTRY alcOpenDevice(const ALCchar *deviceName) //Validate device device->Connected = ALC_TRUE; device->IsCaptureDevice = AL_FALSE; + device->LastError = ALC_NO_ERROR; device->Bs2b = NULL; device->szDeviceName = NULL; @@ -1749,13 +1748,13 @@ ALCAPI ALCdevice* ALCAPIENTRY alcOpenDevice(const ALCchar *deviceName) if (!bDeviceFound) { // No suitable output device found - alcSetError(ALC_INVALID_VALUE); + alcSetError(NULL, ALC_INVALID_VALUE); free(device); device = NULL; } } else - alcSetError(ALC_OUT_OF_MEMORY); + alcSetError(NULL, ALC_OUT_OF_MEMORY); return device; } @@ -1839,7 +1838,7 @@ ALCAPI ALCboolean ALCAPIENTRY alcCloseDevice(ALCdevice *pDevice) bReturn = ALC_TRUE; } else - alcSetError(ALC_INVALID_DEVICE); + alcSetError(pDevice, ALC_INVALID_DEVICE); return bReturn; } |