aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Alc/vector.h10
-rw-r--r--OpenAL32/alSoundfont.c30
2 files changed, 30 insertions, 10 deletions
diff --git a/Alc/vector.h b/Alc/vector.h
index 944cccc2..cc0c84fb 100644
--- a/Alc/vector.h
+++ b/Alc/vector.h
@@ -74,4 +74,14 @@ ALboolean vector_insert(void *ptr, size_t base_size, size_t obj_size, void *ins_
_f(_iter); \
} while(0)
+#define VECTOR_FIND_IF(_i, _t, _x, _f) do { \
+ _t *_end = VECTOR_ITER_END((_x)); \
+ (_i) = VECTOR_ITER_BEGIN((_x)); \
+ for(;(_i) != _end;++(_i)) \
+ { \
+ if(_f(_i)) \
+ break; \
+ } \
+} while(0)
+
#endif /* AL_VECTOR_H */
diff --git a/OpenAL32/alSoundfont.c b/OpenAL32/alSoundfont.c
index 6ba4772c..40a93021 100644
--- a/OpenAL32/alSoundfont.c
+++ b/OpenAL32/alSoundfont.c
@@ -341,9 +341,10 @@ void ALsoundfont_deleteSoundfont(ALsoundfont *self, ALCdevice *device)
{
ALsfpreset **presets;
ALsizei num_presets;
- ALbuffer *buffer = NULL;
+ VECTOR(ALbuffer*) buffers;
ALsizei i;
+ VECTOR_INIT(buffers);
presets = ExchangePtr((XchgPtr*)&self->Presets, NULL);
num_presets = ExchangeInt(&self->NumPresets, 0);
@@ -374,10 +375,17 @@ void ALsoundfont_deleteSoundfont(ALsoundfont *self, ALCdevice *device)
if(sounds[j] && ReadRef(&sounds[j]->ref) == 0)
{
deleting = AL_TRUE;
- if(!buffer)
- buffer = sounds[j]->Buffer;
- else if(sounds[j]->Buffer)
- assert(sounds[j]->Buffer == buffer);
+ if(sounds[j]->Buffer)
+ {
+ ALbuffer *buffer = sounds[j]->Buffer;
+ ALbuffer **iter;
+
+#define MATCH_BUFFER(_i) (buffer == *(_i))
+ VECTOR_FIND_IF(iter, ALbuffer*, buffers, MATCH_BUFFER);
+ if(iter == VECTOR_ITER_END(buffers))
+ VECTOR_PUSH_BACK(buffers, buffer);
+#undef MATCH_BUFFER
+ }
DeleteFontsound(device, sounds[j]);
sounds[j] = NULL;
}
@@ -389,11 +397,13 @@ void ALsoundfont_deleteSoundfont(ALsoundfont *self, ALCdevice *device)
ALsoundfont_Destruct(self);
free(self);
- if(buffer)
- {
- assert(ReadRef(&buffer->ref) == 0);
- DeleteBuffer(device, buffer);
- }
+#define DELETE_BUFFER(iter) do { \
+ assert(ReadRef(&(*(iter))->ref) == 0); \
+ DeleteBuffer(device, *(iter)); \
+} while(0)
+ VECTOR_FOR_EACH(ALbuffer*, buffers, DELETE_BUFFER);
+ VECTOR_DEINIT(buffers);
+#undef DELETE_BUFFER
}