Skip to content

Commit

Permalink
Increase buffer reference count when they are queued.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Apr 3, 2018
1 parent 73dfb0a commit ff9d6e2
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion mojoal.c
Expand Up @@ -253,7 +253,7 @@ typedef struct BufferBlock

typedef struct BufferQueueItem
{
const ALbuffer *buffer;
ALbuffer *buffer;
void *next; /* void* because we'll atomicgetptr it. */
} BufferQueueItem;

Expand Down Expand Up @@ -2554,6 +2554,9 @@ void alSourceQueueBuffers(ALuint name, ALsizei nb, const ALuint *bufnames)
}
}

if (buffer) {
SDL_AtomicIncRef(&buffer->refcount); /* mark it as in-use. */
}
item->buffer = buffer;

SDL_assert((queue != NULL) == (queueend != NULL));
Expand Down Expand Up @@ -2592,6 +2595,14 @@ void alSourceQueueBuffers(ALuint name, ALsizei nb, const ALuint *bufnames)

if (failed) {
if (queue) {
/* Drop our claim on any buffers we planned to queue. */
BufferQueueItem *item;
for (item = queue; item != NULL; item = item->next) {
if (item->buffer) {
(void) SDL_AtomicDecRef(&item->buffer->refcount);
}
}

/* put the whole new queue back in the pool for reuse later. */
do {
ptr = SDL_AtomicGetPtr(&ctx->device->playback.buffer_queue_pool);
Expand Down Expand Up @@ -2686,6 +2697,9 @@ void alSourceUnqueueBuffers(ALuint name, ALsizei nb, ALuint *bufnames)

item = queue;
for (i = 0; i < nb; i++) {
if (item->buffer) {
(void) SDL_AtomicDecRef(&item->buffer->refcount);
}
bufnames[i] = item->buffer ? item->buffer->name : 0;
queueend = item;
item = item->next;
Expand Down

0 comments on commit ff9d6e2

Please sign in to comment.