aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-11-25 15:30:32 -0800
committerChris Robinson <[email protected]>2018-11-25 15:30:32 -0800
commit8ae07ad1ae2d957f65ba54fdcd19649eceeb0e3d (patch)
treeb26085490d71fdb2e0968bfd79c90c3dd3613764
parent05845b53e889c2104a5436ff5418c5e2ba5dcbf3 (diff)
Automatically clean up buffers with ther sublist
-rw-r--r--Alc/alc.cpp10
-rw-r--r--OpenAL32/Include/alBuffer.h2
-rw-r--r--OpenAL32/Include/alMain.h16
-rw-r--r--OpenAL32/alBuffer.cpp32
-rw-r--r--OpenAL32/alSource.cpp5
5 files changed, 28 insertions, 37 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp
index 5fae13b3..34279269 100644
--- a/Alc/alc.cpp
+++ b/Alc/alc.cpp
@@ -2396,11 +2396,11 @@ ALCdevice_struct::~ALCdevice_struct()
almtx_destroy(&BackendLock);
- ReleaseALBuffers(this);
- std::for_each(BufferList.begin(), BufferList.end(),
- [](BufferSubList &entry) noexcept -> void
- { al_free(entry.Buffers); }
- );
+ size_t count{0u};
+ for(auto &sublist : BufferList)
+ count += POPCNT64(~sublist.FreeMask);
+ if(count > 0)
+ WARN(SZFMT " Buffer%s not deleted\n", count, (count==1)?"":"s");
BufferList.clear();
almtx_destroy(&BufferLock);
diff --git a/OpenAL32/Include/alBuffer.h b/OpenAL32/Include/alBuffer.h
index 54c17670..691c7e22 100644
--- a/OpenAL32/Include/alBuffer.h
+++ b/OpenAL32/Include/alBuffer.h
@@ -121,6 +121,4 @@ struct ALbuffer {
ALuint id{0};
};
-ALvoid ReleaseALBuffers(ALCdevice *device);
-
#endif
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 5ff1e064..eae3ea99 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -551,10 +551,20 @@ typedef union AmbiConfig {
} AmbiConfig;
-typedef struct BufferSubList {
- ALuint64 FreeMask{~ALuint64{}};
+struct BufferSubList {
+ uint64_t FreeMask{~uint64_t{}};
struct ALbuffer *Buffers{nullptr}; /* 64 */
-} BufferSubList;
+
+ BufferSubList() noexcept = default;
+ BufferSubList(const BufferSubList&) = delete;
+ BufferSubList(BufferSubList&& rhs) noexcept : FreeMask{rhs.FreeMask}, Buffers{rhs.Buffers}
+ { rhs.FreeMask = ~uint64_t{}; rhs.Buffers = nullptr; }
+ ~BufferSubList();
+
+ BufferSubList& operator=(const BufferSubList&) = delete;
+ BufferSubList& operator=(BufferSubList&& rhs) noexcept
+ { std::swap(FreeMask, rhs.FreeMask); std::swap(Buffers, rhs.Buffers); return *this; }
+};
typedef struct EffectSubList {
ALuint64 FreeMask{~ALuint64{}};
diff --git a/OpenAL32/alBuffer.cpp b/OpenAL32/alBuffer.cpp
index 5c40a27e..3716ac28 100644
--- a/OpenAL32/alBuffer.cpp
+++ b/OpenAL32/alBuffer.cpp
@@ -1174,30 +1174,16 @@ ALsizei ChannelsFromFmt(FmtChannels chans)
}
-/*
- * ReleaseALBuffers()
- *
- * INTERNAL: Called to destroy any buffers that still exist on the device
- */
-ALvoid ReleaseALBuffers(ALCdevice *device)
+BufferSubList::~BufferSubList()
{
- size_t leftover = 0;
- for(auto &sublist : device->BufferList)
+ ALuint64 usemask = ~FreeMask;
+ while(usemask)
{
- ALuint64 usemask = ~sublist.FreeMask;
- while(usemask)
- {
- ALsizei idx = CTZ64(usemask);
- ALbuffer *buffer = sublist.Buffers + idx;
-
- buffer->~ALbuffer();
-
- ++leftover;
-
- usemask &= ~(U64(1) << idx);
- }
- sublist.FreeMask = ~usemask;
+ ALsizei idx{CTZ64(usemask)};
+ Buffers[idx].~ALbuffer();
+ usemask &= ~(U64(1) << idx);
}
- if(leftover > 0)
- WARN("(%p) Deleted " SZFMT " Buffer%s\n", device, leftover, (leftover==1)?"":"s");
+ FreeMask = ~usemask;
+ al_free(Buffers);
+ Buffers = nullptr;
}
diff --git a/OpenAL32/alSource.cpp b/OpenAL32/alSource.cpp
index 8b461982..12a8a04a 100644
--- a/OpenAL32/alSource.cpp
+++ b/OpenAL32/alSource.cpp
@@ -3405,10 +3405,7 @@ SourceSubList::~SourceSubList()
while(usemask)
{
ALsizei idx{CTZ64(usemask)};
- ALsource *source{Sources + idx};
-
- source->~ALsource();
-
+ Sources[idx].~ALsource();
usemask &= ~(U64(1) << idx);
}
FreeMask = ~usemask;