From 1717c62f258c3cad297e9d066da7cbe57f8be200 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Thu, 15 Jun 2023 18:14:02 -0700 Subject: Changeset: 98 Cleanup and prepare for rewriting shader system --- source/10-common/RingBuffer.hpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'source/10-common/RingBuffer.hpp') diff --git a/source/10-common/RingBuffer.hpp b/source/10-common/RingBuffer.hpp index de8227c..4eaa007 100644 --- a/source/10-common/RingBuffer.hpp +++ b/source/10-common/RingBuffer.hpp @@ -72,7 +72,7 @@ public: RingBuffer() noexcept = default; ~RingBuffer() noexcept { - delete mRing; + delete[] mRing; } RingBuffer(const RingBuffer&) noexcept = delete; @@ -128,6 +128,7 @@ public: [[nodiscard]] T& operator[](size_type i) { return const_cast(const_cast(*this)[i]); } [[nodiscard]] const T& operator[](size_type i) const { + assert(mRing != nullptr); size_type idx = mHeadIdx + i; if (idx >= mCapacity) { idx -= mCapacity; @@ -136,6 +137,7 @@ public: } void push_back(T t) { + assert(mRing != nullptr); if (mTailIdx == mCapacity) { // Ring buffer is filled to the right, warp around to the beginning // mHeadIdx > 0 must be true, since we checked that as condition (1) above @@ -177,8 +179,10 @@ public: auto oldRing = mRing; auto newRing = mRing = new T[newCapacity]; - std::rotate_copy(oldRing, oldRing + mHeadIdx, oldRing + mCapacity, newRing); - delete oldRing; + if (oldRing != nullptr) { + std::rotate_copy(oldRing, oldRing + mHeadIdx, oldRing + mCapacity, newRing); + delete[] oldRing; + } mCapacity = newCapacity; mHeadIdx = 0; -- cgit v1.2.3-70-g09d2