AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots) { ALCcontext *Context; Context = GetContextRef(); if(!Context) return; if(n < 0 || IsBadWritePtr((void*)effectslots, n * sizeof(ALuint))) alSetError(Context, AL_INVALID_VALUE); else { ALenum err; ALsizei i; err = ResizeEffectSlotArray(Context, n); if(err != AL_NO_ERROR) { alSetError(Context, err); n = 0; } for(i = 0;i < n;i++) { ALeffectslot *slot = calloc(1, sizeof(ALeffectslot)); if(!slot || InitEffectSlot(slot) != AL_NO_ERROR) { free(slot); // We must have run out or memory alSetError(Context, AL_OUT_OF_MEMORY); alDeleteAuxiliaryEffectSlots(i, effectslots); break; } LockContext(Context); err = ResizeEffectSlotArray(Context, 1); if(err == AL_NO_ERROR) Context->ActiveEffectSlots[Context->ActiveEffectSlotCount++] = slot; UnlockContext(Context); if(err == AL_NO_ERROR) err = NewThunkEntry(&slot->effectslot); if(err == AL_NO_ERROR) err = InsertUIntMapEntry(&Context->EffectSlotMap, slot->effectslot, slot); if(err != AL_NO_ERROR) { RemoveEffectSlotArray(Context, slot); FreeThunkEntry(slot->effectslot); ALeffectState_Destroy(slot->EffectState); free(slot); alSetError(Context, err); alDeleteAuxiliaryEffectSlots(i, effectslots); break; } effectslots[i] = slot->effectslot; } } ALCcontext_DecRef(Context); }
AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots) { ALCcontext *context; VECTOR(ALeffectslot*) slotvec; ALsizei cur; ALenum err; context = GetContextRef(); if(!context) return; VECTOR_INIT(slotvec); if(!(n >= 0)) SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); if(!VECTOR_RESERVE(slotvec, n)) SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done); for(cur = 0;cur < n;cur++) { ALeffectslot *slot = al_calloc(16, sizeof(ALeffectslot)); err = AL_OUT_OF_MEMORY; if(!slot || (err=InitEffectSlot(slot)) != AL_NO_ERROR) { al_free(slot); alDeleteAuxiliaryEffectSlots(cur, effectslots); SET_ERROR_AND_GOTO(context, err, done); } err = NewThunkEntry(&slot->id); if(err == AL_NO_ERROR) err = InsertUIntMapEntry(&context->EffectSlotMap, slot->id, slot); if(err != AL_NO_ERROR) { FreeThunkEntry(slot->id); DELETE_OBJ(slot->Params.EffectState); al_free(slot); alDeleteAuxiliaryEffectSlots(cur, effectslots); SET_ERROR_AND_GOTO(context, err, done); } aluInitEffectPanning(slot); VECTOR_PUSH_BACK(slotvec, slot); effectslots[cur] = slot->id; } err = AddEffectSlotArray(context, VECTOR_BEGIN(slotvec), n); if(err != AL_NO_ERROR) { alDeleteAuxiliaryEffectSlots(cur, effectslots); SET_ERROR_AND_GOTO(context, err, done); } done: VECTOR_DEINIT(slotvec); ALCcontext_DecRef(context); }
AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots) { ALCcontext *context; ALeffectslot *first, *last; ALsizei cur; ALenum err; context = GetContextRef(); if(!context) return; if(!(n >= 0)) SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); first = last = NULL; for(cur = 0;cur < n;cur++) { ALeffectslot *slot = al_calloc(16, sizeof(ALeffectslot)); err = AL_OUT_OF_MEMORY; if(!slot || (err=InitEffectSlot(slot)) != AL_NO_ERROR) { al_free(slot); alDeleteAuxiliaryEffectSlots(cur, effectslots); SET_ERROR_AND_GOTO(context, err, done); } err = NewThunkEntry(&slot->id); if(err == AL_NO_ERROR) err = InsertUIntMapEntry(&context->EffectSlotMap, slot->id, slot); if(err != AL_NO_ERROR) { FreeThunkEntry(slot->id); DELETE_OBJ(slot->Params.EffectState); al_free(slot); alDeleteAuxiliaryEffectSlots(cur, effectslots); SET_ERROR_AND_GOTO(context, err, done); } aluInitEffectPanning(slot); if(!first) first = slot; if(last) ATOMIC_STORE(&last->next, slot); last = slot; effectslots[cur] = slot->id; } AddEffectSlotList(context, first, last); done: ALCcontext_DecRef(context); }
AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots) { ALCcontext *Context; ALsizei cur = 0; Context = GetContextRef(); if(!Context) return; al_try { ALenum err; CHECK_VALUE(Context, n >= 0); for(cur = 0;cur < n;cur++) { ALeffectslot *slot = al_calloc(16, sizeof(ALeffectslot)); err = AL_OUT_OF_MEMORY; if(!slot || (err=InitEffectSlot(slot)) != AL_NO_ERROR) { al_free(slot); al_throwerr(Context, err); break; } err = NewThunkEntry(&slot->id); if(err == AL_NO_ERROR) err = InsertUIntMapEntry(&Context->EffectSlotMap, slot->id, slot); if(err != AL_NO_ERROR) { FreeThunkEntry(slot->id); ALeffectState_Destroy(slot->EffectState); al_free(slot); al_throwerr(Context, err); } effectslots[cur] = slot->id; } err = AddEffectSlotArray(Context, n, effectslots); if(err != AL_NO_ERROR) al_throwerr(Context, err); } al_catchany() { if(cur > 0) alDeleteAuxiliaryEffectSlots(cur, effectslots); } al_endtry; ALCcontext_DecRef(Context); }
AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots) { ALCdevice *device; ALCcontext *context; ALsizei cur; context = GetContextRef(); if(!context) return; if(n < 0) SETERR_GOTO(context, AL_INVALID_VALUE, done, "Generating %d effect slots", n); if(n == 0) goto done; LockEffectSlotList(context); device = context->Device; for(cur = 0;cur < n;cur++) { ALeffectslotPtr *iter = VECTOR_BEGIN(context->EffectSlotList); ALeffectslotPtr *end = VECTOR_END(context->EffectSlotList); ALeffectslot *slot = NULL; ALenum err = AL_OUT_OF_MEMORY; for(;iter != end;iter++) { if(!*iter) break; } if(iter == end) { if(device->AuxiliaryEffectSlotMax == VECTOR_SIZE(context->EffectSlotList)) { UnlockEffectSlotList(context); alDeleteAuxiliaryEffectSlots(cur, effectslots); SETERR_GOTO(context, AL_OUT_OF_MEMORY, done, "Exceeding %u auxiliary effect slot limit", device->AuxiliaryEffectSlotMax); } VECTOR_PUSH_BACK(context->EffectSlotList, NULL); iter = &VECTOR_BACK(context->EffectSlotList); } slot = al_calloc(16, sizeof(ALeffectslot)); if(!slot || (err=InitEffectSlot(slot)) != AL_NO_ERROR) { al_free(slot); UnlockEffectSlotList(context); alDeleteAuxiliaryEffectSlots(cur, effectslots); SETERR_GOTO(context, err, done, "Effect slot object allocation failed"); } aluInitEffectPanning(slot); slot->id = (iter - VECTOR_BEGIN(context->EffectSlotList)) + 1; *iter = slot; effectslots[cur] = slot->id; } AddActiveEffectSlots(effectslots, n, context); UnlockEffectSlotList(context); done: ALCcontext_DecRef(context); }