Skip to content

Commit

Permalink
Fixed silly logic bug in buffer/source generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jul 1, 2019
1 parent fb3499a commit a9a96be
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions mojoal.c
Expand Up @@ -2482,6 +2482,8 @@ static ALsource *get_source(ALCcontext *ctx, const ALuint name, SourceBlock **_b
ALsource *source;
SourceBlock *block;

/*printf("get_source(%d): blockidx=%d, block_offset=%d\n", (int) name, (int) blockidx, (int) block_offset);*/

if (!ctx) {
set_al_error(ctx, AL_INVALID_OPERATION);
if (_block) *_block = NULL;
Expand Down Expand Up @@ -2512,6 +2514,8 @@ static ALbuffer *get_buffer(ALCcontext *ctx, const ALuint name, BufferBlock **_b
ALbuffer *buffer;
BufferBlock *block;

/*printf("get_buffer(%d): blockidx=%d, block_offset=%d\n", (int) name, (int) blockidx, (int) block_offset);*/

if (!ctx) {
set_al_error(ctx, AL_INVALID_OPERATION);
if (_block) *_block = NULL;
Expand Down Expand Up @@ -3229,11 +3233,13 @@ static void _alGenSources(const ALsizei n, ALuint *names)
block->tmp = 0;
if (block->used < SDL_arraysize(block->sources)) { /* skip if full */
for (i = 0; i < SDL_arraysize(block->sources); i++) {
block->tmp++;
objects[found] = &block->sources[i];
names[found++] = (i + block_offset) + 1; /* +1 so it isn't zero. */
if (found == n) {
break;
if (!block->sources[i].allocated) {
block->tmp++;
objects[found] = &block->sources[i];
names[found++] = (i + block_offset) + 1; /* +1 so it isn't zero. */
if (found == n) {
break;
}
}
}

Expand Down Expand Up @@ -3303,6 +3309,10 @@ static void _alGenSources(const ALsizei n, ALuint *names)
for (i = 0; i < n; i++) {
ALsource *src = objects[i];

/*printf("Generated source %u\n", (unsigned int) names[i]);*/

SDL_assert(!src->allocated);

/* Make sure everything that wants to use SIMD is aligned for it. */
SDL_assert( (((size_t) &src->position[0]) % 16) == 0 );
SDL_assert( (((size_t) &src->velocity[0]) % 16) == 0 );
Expand Down Expand Up @@ -4146,11 +4156,13 @@ static void _alGenBuffers(const ALsizei n, ALuint *names)
block->tmp = 0;
if (block->used < SDL_arraysize(block->buffers)) { /* skip if full */
for (i = 0; i < SDL_arraysize(block->buffers); i++) {
block->tmp++;
objects[found] = &block->buffers[i];
names[found++] = (i + block_offset) + 1; /* +1 so it isn't zero. */
if (found == n) {
break;
if (!block->buffers[i].allocated) {
block->tmp++;
objects[found] = &block->buffers[i];
names[found++] = (i + block_offset) + 1; /* +1 so it isn't zero. */
if (found == n) {
break;
}
}
}

Expand Down Expand Up @@ -4219,6 +4231,8 @@ static void _alGenBuffers(const ALsizei n, ALuint *names)

for (i = 0; i < n; i++) {
ALbuffer *buffer = objects[i];
/*printf("Generated buffer %u\n", (unsigned int) names[i]);*/
SDL_assert(!buffer->allocated);
SDL_zerop(buffer);
buffer->name = names[i];
buffer->channels = 1;
Expand Down

0 comments on commit a9a96be

Please sign in to comment.