diff options
author | Chris Robinson <[email protected]> | 2008-07-11 09:12:11 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2008-07-11 09:12:11 -0700 |
commit | 97d3a45aff582242a9e5229c1e170f45ac96e0d9 (patch) | |
tree | 23920261f18dff973850a37037ed4d97ec7cdc21 /OpenAL32 | |
parent | 9e9ff44b176578035be146f89c5a06258cb6a019 (diff) |
Don't check the number of objects being deleted with the number currently allocated
Since apps can validly delete buffer 0, and delete the same source/buffer multiple times in a single call
Diffstat (limited to 'OpenAL32')
-rw-r--r-- | OpenAL32/alBuffer.c | 76 | ||||
-rw-r--r-- | OpenAL32/alSource.c | 97 |
2 files changed, 80 insertions, 93 deletions
diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c index 84f29508..8934f878 100644 --- a/OpenAL32/alBuffer.c +++ b/OpenAL32/alBuffer.c @@ -142,63 +142,59 @@ ALAPI ALvoid ALAPIENTRY alDeleteBuffers(ALsizei n, const ALuint *puiBuffers) // Check we are actually Deleting some Buffers if (n >= 0) { - if ((ALuint)n <= g_uiBufferCount) + // Check that all the buffers are valid and can actually be deleted + for (i = 0; i < n; i++) { - // Check that all the buffers are valid and can actually be deleted - for (i = 0; i < n; i++) + // Check for valid Buffer ID (can be NULL buffer) + if (alIsBuffer(puiBuffers[i])) { - // Check for valid Buffer ID (can be NULL buffer) - if (alIsBuffer(puiBuffers[i])) + // If not the NULL buffer, check that the reference count is 0 + ALBuf = ((ALbuffer *)ALTHUNK_LOOKUPENTRY(puiBuffers[i])); + if (ALBuf) { - // If not the NULL buffer, check that the reference count is 0 - ALBuf = ((ALbuffer *)ALTHUNK_LOOKUPENTRY(puiBuffers[i])); - if (ALBuf) + if (ALBuf->refcount != 0) { - if (ALBuf->refcount != 0) - { - // Buffer still in use, cannot be deleted - alSetError(AL_INVALID_OPERATION); - bFailed = AL_TRUE; - } + // Buffer still in use, cannot be deleted + alSetError(AL_INVALID_OPERATION); + bFailed = AL_TRUE; } } - else - { - // Invalid Buffer - alSetError(AL_INVALID_NAME); - bFailed = AL_TRUE; - } } + else + { + // Invalid Buffer + alSetError(AL_INVALID_NAME); + bFailed = AL_TRUE; + } + } - // If all the Buffers were valid (and have Reference Counts of 0), then we can delete them - if (!bFailed) + // If all the Buffers were valid (and have Reference Counts of 0), then we can delete them + if (!bFailed) + { + for (i = 0; i < n; i++) { - for (i = 0; i < n; i++) + if (puiBuffers[i] && alIsBuffer(puiBuffers[i])) { + ALbuffer **list = &g_pBuffers; + ALBuf=((ALbuffer *)ALTHUNK_LOOKUPENTRY(puiBuffers[i])); - if (ALBuf) - { - ALbuffer **list = &g_pBuffers; - while(*list && *list != ALBuf) - list = &(*list)->next; + while(*list && *list != ALBuf) + list = &(*list)->next; - if(*list) - *list = (*list)->next; + if(*list) + *list = (*list)->next; - // Release the memory used to store audio data - free(ALBuf->data); + // Release the memory used to store audio data + free(ALBuf->data); - // Release buffer structure - ALTHUNK_REMOVEENTRY(puiBuffers[i]); - memset(ALBuf, 0, sizeof(ALbuffer)); - g_uiBufferCount--; - free(ALBuf); - } + // Release buffer structure + ALTHUNK_REMOVEENTRY(puiBuffers[i]); + memset(ALBuf, 0, sizeof(ALbuffer)); + g_uiBufferCount--; + free(ALBuf); } } } - else - alSetError(AL_INVALID_NAME); } else alSetError(AL_INVALID_VALUE); diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c index df78de33..88c699cd 100644 --- a/OpenAL32/alSource.c +++ b/OpenAL32/alSource.c @@ -137,74 +137,65 @@ ALAPI ALvoid ALAPIENTRY alDeleteSources(ALsizei n, const ALuint *sources) if (Device) { - if ((ALuint)n <= Context->SourceCount) + // Check that all Sources are valid (and can therefore be deleted) + for (i = 0; i < n; i++) { - // Check that all Sources are valid (and can therefore be deleted) - for (i = 0; i < n; i++) + if (!alIsSource(sources[i])) { - if (!alIsSource(sources[i])) - { - alSetError(AL_INVALID_NAME); - bSourcesValid = AL_FALSE; - break; - } + alSetError(AL_INVALID_NAME); + bSourcesValid = AL_FALSE; + break; } + } - if (bSourcesValid) + if (bSourcesValid) + { + // All Sources are valid, and can be deleted + for (i = 0; i < n; i++) { - // All Sources are valid, and can be deleted - for (i = 0; i < n; i++) + // Recheck that the Source is valid, because there could be duplicated Source names + if (alIsSource(sources[i])) { - // Recheck that the Source is valid, because there could be duplicated Source names - if (alIsSource(sources[i])) - { - ALSource=((ALsource *)ALTHUNK_LOOKUPENTRY(sources[i])); - alSourceStop((ALuint)ALSource->source); + ALSource=((ALsource *)ALTHUNK_LOOKUPENTRY(sources[i])); + alSourceStop((ALuint)ALSource->source); - // For each buffer in the source's queue, decrement its reference counter and remove it - while (ALSource->queue != NULL) - { - ALBufferList = ALSource->queue; - // Decrement buffer's reference counter - if (ALBufferList->buffer != 0) - ((ALbuffer*)(ALTHUNK_LOOKUPENTRY(ALBufferList->buffer)))->refcount--; - // Update queue to point to next element in list - ALSource->queue = ALBufferList->next; - // Release memory allocated for buffer list item - free(ALBufferList); - } + // For each buffer in the source's queue, decrement its reference counter and remove it + while (ALSource->queue != NULL) + { + ALBufferList = ALSource->queue; + // Decrement buffer's reference counter + if (ALBufferList->buffer != 0) + ((ALbuffer*)(ALTHUNK_LOOKUPENTRY(ALBufferList->buffer)))->refcount--; + // Update queue to point to next element in list + ALSource->queue = ALBufferList->next; + // Release memory allocated for buffer list item + free(ALBufferList); + } - for(j = 0;j < MAX_SENDS;++j) - { - if(ALSource->Send[j].Slot) - ALSource->Send[j].Slot->refcount--; - ALSource->Send[j].Slot = NULL; - } + for(j = 0;j < MAX_SENDS;++j) + { + if(ALSource->Send[j].Slot) + ALSource->Send[j].Slot->refcount--; + ALSource->Send[j].Slot = NULL; + } - // Decrement Source count - Context->SourceCount--; + // Decrement Source count + Context->SourceCount--; - // Remove Source from list of Sources - list = &Context->Source; - while(*list && *list != ALSource) - list = &(*list)->next; + // Remove Source from list of Sources + list = &Context->Source; + while(*list && *list != ALSource) + list = &(*list)->next; - if(*list) - *list = (*list)->next; - ALTHUNK_REMOVEENTRY(ALSource->source); + if(*list) + *list = (*list)->next; + ALTHUNK_REMOVEENTRY(ALSource->source); - memset(ALSource,0,sizeof(ALsource)); - free(ALSource); - } + memset(ALSource,0,sizeof(ALsource)); + free(ALSource); } - } } - else - { - // Trying to delete more Sources than have been generated - alSetError(AL_INVALID_NAME); - } } else { |