Skip to content

Commit

Permalink
Fix in VmaBlockMetadata_Linear::CreateAllocationRequest for too large…
Browse files Browse the repository at this point in the history
… allocations

Fixes #396 - thanks @dm-tesla
  • Loading branch information
adam-sawicki-a committed Feb 23, 2024
1 parent 9b76877 commit f1ab507
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/vk_mem_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -7808,6 +7808,10 @@ bool VmaBlockMetadata_Linear::CreateAllocationRequest(
VMA_ASSERT(allocType != VMA_SUBALLOCATION_TYPE_FREE);
VMA_ASSERT(pAllocationRequest != VMA_NULL);
VMA_HEAVY_ASSERT(Validate());

if(allocSize > GetSize())
return false;

pAllocationRequest->size = allocSize;
return upperAddress ?
CreateAllocationRequest_UpperAddress(
Expand Down
8 changes: 8 additions & 0 deletions src/Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3425,6 +3425,14 @@ static void TestVirtualBlocksAlgorithms()
};
std::vector<AllocData> allocations;

// Test too large allocation
{
VmaVirtualAllocationCreateInfo allocCreateInfo = {};
allocCreateInfo.size = blockCreateInfo.size * 2;
VmaVirtualAllocation alloc;
TEST(vmaVirtualAllocate(block, &allocCreateInfo, &alloc, nullptr) < 0);
}

// Make some allocations
for(size_t i = 0; i < 20; ++i)
{
Expand Down

0 comments on commit f1ab507

Please sign in to comment.