Skip to content

Commit

Permalink
Hack[vma]: enforce pointer alignment for VMA_SYSTEM_ALIGNED_MALLOC
Browse files Browse the repository at this point in the history
  • Loading branch information
artdeell authored Jan 10, 2025
1 parent 02b47ed commit eaf694d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions modules/lwjgl/vma/src/main/c/vk_mem_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -3815,6 +3815,12 @@ static void* VmaMalloc(const VkAllocationCallbacks* pAllocationCallbacks, size_t
}
else
{
// HACK: enforce at least pointer alignment for system malloc
// LWJGL installs its own malloc callbacks, one of which calls aligned_alloc straight
// from the VMA_SYSTEM_ALIGNED_ALLOC define. The problem is that aligned_alloc
// uses posix_memalign for memory allocation on Android, which leads to a crash since sometimes
// VMA attempts to allocate pages with an alignment of 2 (not supported by posix_memalign)
if(alignment <= sizeof(void*)) alignment = sizeof(void*);
result = VMA_SYSTEM_ALIGNED_MALLOC(size, alignment);
}
VMA_ASSERT(result != VMA_NULL && "CPU memory allocation failed.");
Expand Down

0 comments on commit eaf694d

Please sign in to comment.