Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Source/astcenc_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ astcenc_error astcenc_context_alloc(
{
if (ctx->owns_bsd)
{
aligned_free<const block_size_descriptor>(ctx->bsd);
aligned_free<const block_size_descriptor>(ctx->bsd, ASTCENC_VECALIGN);
}
delete ctxo;
*context = nullptr;
Expand Down Expand Up @@ -836,10 +836,10 @@ void astcenc_context_free(
if (ctxo)
{
astcenc_contexti* ctx = &ctxo->context;
aligned_free<compression_working_buffers>(ctx->working_buffers);
aligned_free<compression_working_buffers>(ctx->working_buffers, ASTCENC_VECALIGN);
if (ctx->owns_bsd)
{
aligned_free<const block_size_descriptor>(ctx->bsd);
aligned_free<const block_size_descriptor>(ctx->bsd, ASTCENC_VECALIGN);
}
#if defined(ASTCENC_DIAGNOSTICS)
delete ctx->trace_log;
Expand Down
15 changes: 12 additions & 3 deletions Source/astcenc_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <cstdlib>
#include <limits>
#include <type_traits>
#include <new>

#include "astcenc.h"
#include "astcenc_mathlib.h"
Expand Down Expand Up @@ -2319,7 +2320,9 @@ T* aligned_malloc(size_t size, size_t align)
size_t min_align = astc::max(alignof(T), sizeof(void*));
size_t real_align = astc::max(min_align, align);

#if defined(_WIN32)
#if (__cplusplus >= 201703L || _MSVC_LANG >= 201703L)
ptr = ::operator new(size, std::align_val_t{real_align});
#elif defined(_WIN32)
ptr = _aligned_malloc(size, real_align);
#else
error = posix_memalign(&ptr, real_align, size);
Expand All @@ -2341,9 +2344,15 @@ T* aligned_malloc(size_t size, size_t align)
* @param ptr The buffer to free.
*/
template<typename T>
void aligned_free(T* ptr)
void aligned_free(T* ptr, size_t align)
{
#if defined(_WIN32)
#if (__cplusplus >= 201703L || _MSVC_LANG >= 201703L)
// Don't allow this to under-align a type
size_t min_align = astc::max(alignof(T), sizeof(void*));
size_t real_align = astc::max(min_align, align);

::operator delete(const_cast<typename std::remove_const<T>::type *>(ptr), std::align_val_t{real_align});
#elif defined(_WIN32)
_aligned_free(const_cast<typename std::remove_const<T>::type *>(ptr));
#else
free(const_cast<typename std::remove_const<T>::type *>(ptr));
Expand Down
Loading