From d590e2e94ffb7b75af0a86a7790372c9c2ba1823 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sun, 19 Oct 2025 12:05:58 -0500 Subject: [PATCH] fix(array): correct implementation of TSFixedArray::ReallocAndClearData --- storm/array/TSFixedArray.hpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/storm/array/TSFixedArray.hpp b/storm/array/TSFixedArray.hpp index 0435f2c..4f39d51 100644 --- a/storm/array/TSFixedArray.hpp +++ b/storm/array/TSFixedArray.hpp @@ -60,11 +60,20 @@ void TSFixedArray::Clear() { template void TSFixedArray::ReallocAndClearData(uint32_t count) { - this->m_alloc = count; + // Destruct existing array elements + for (uint32_t i = 0; i < this->Count(); i++) { + auto element = &this->operator[](i); + element->~T(); + } - if (this->m_data || count) { - void* m = SMemReAlloc(this->m_data, sizeof(T) * count, this->MemFileName(), this->MemLineNo(), 0x0); - this->m_data = static_cast(m); + // Reallocate if count changed + if (count != this->m_count) { + this->m_alloc = count; + + if (this->m_data || count) { + void* m = SMemReAlloc(this->m_data, sizeof(T) * count, this->MemFileName(), this->MemLineNo(), 0x0); + this->m_data = static_cast(m); + } } }