diff --git a/Include/Aurora/Memory/Heap.hpp b/Include/Aurora/Memory/Heap.hpp index 997fccd1..0abacc6e 100644 --- a/Include/Aurora/Memory/Heap.hpp +++ b/Include/Aurora/Memory/Heap.hpp @@ -134,6 +134,26 @@ namespace Aurora::Memory pHeap->_Free(pVoids); } + + template + static void DeleteThatCastedOnce(T *pThat) + { + static const auto kAlignment = AuMax(alignof(T), sizeof(void *)); + + auto pBaseClass = AuStaticCast(pThat); + + if constexpr (AuIsClass_v + #if !defined(AURT_HEAP_NO_STL) + && !std::is_trivially_destructible_v + #endif + ) + { + pBaseClass->~Z(); + } + + auto &pHeap = *(Heap **)(((char *)pBaseClass) - kAlignment); + pHeap->_Free(&pHeap); + } template static void RetardedSpecWrittenByRetards(T *pThat) @@ -354,10 +374,13 @@ namespace Aurora::Memory { return NullUniquePointer(); } + else if (pInPointer.get_deleter() == &Heap::DeleteThat) + { + return AuUPtr)>(AuStaticCast(pInPointer.release()), &Heap::DeleteThatCastedOnce); + } else { - auto deleter = decltype(&Heap::DeleteThat)(pInPointer.get_deleter()); - return AuUPtr)>(AuStaticCast(pInPointer.release()), deleter); + return NullUniquePointer(); } }