Fixed vmaVirtualFree legal to call with allocation == VK_NULL_HANDLE
Hopefully fixes #230
Fixes in internal validation.
Rebuilt the docs.
diff --git a/docs/html/group__group__virtual.html b/docs/html/group__group__virtual.html
index 8d6a883..79b0eb8 100644
--- a/docs/html/group__group__virtual.html
+++ b/docs/html/group__group__virtual.html
@@ -610,7 +610,7 @@
</div><div class="memdoc">
<p>Allocates new virtual allocation inside given <a class="el" href="struct_vma_virtual_block.html" title="Handle to a virtual block object that allows to use core allocation algorithm without allocating any ...">VmaVirtualBlock</a>. </p>
-<p >If the allocation fails due to not enough free space available, <code>VK_ERROR_OUT_OF_DEVICE_MEMORY</code> is returned (despite the function doesn't ever allocate actual GPU memory). <code>pAllocation</code> is then set to <code>VK_NULL_HANDLE</code> AND <code>pOffset</code>, if not null, it set to <code>UINT64_MAX</code>.</p>
+<p >If the allocation fails due to not enough free space available, <code>VK_ERROR_OUT_OF_DEVICE_MEMORY</code> is returned (despite the function doesn't ever allocate actual GPU memory). <code>pAllocation</code> is then set to <code>VK_NULL_HANDLE</code> and <code>pOffset</code>, if not null, it set to <code>UINT64_MAX</code>.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir"></td><td class="paramname">virtualBlock</td><td>Virtual block </td></tr>
@@ -650,6 +650,7 @@
</div><div class="memdoc">
<p>Frees virtual allocation inside given <a class="el" href="struct_vma_virtual_block.html" title="Handle to a virtual block object that allows to use core allocation algorithm without allocating any ...">VmaVirtualBlock</a>. </p>
+<p >It is correct to call this function with <code>allocation == VK_NULL_HANDLE</code> - it does nothing. </p>
</div>
</div>
diff --git a/docs/html/struct_vma_virtual_allocation.html b/docs/html/struct_vma_virtual_allocation.html
index bfbfd39..9744aa2 100644
--- a/docs/html/struct_vma_virtual_allocation.html
+++ b/docs/html/struct_vma_virtual_allocation.html
@@ -72,7 +72,8 @@
<p><code>#include <vk_mem_alloc.h></code></p>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p >Represents single memory allocation done inside <a class="el" href="struct_vma_virtual_block.html" title="Handle to a virtual block object that allows to use core allocation algorithm without allocating any ...">VmaVirtualBlock</a>. </p>
-<p >Use it as a unique identifier to virtual allocation within the single block. </p>
+<p >Use it as a unique identifier to virtual allocation within the single block.</p>
+<p >Use value <code>VK_NULL_HANDLE</code> to represent a null/invalid allocation. </p>
</div><hr/>The documentation for this struct was generated from the following file:<ul>
<li>D:/PROJECTS/Vulkan Memory Allocator/REPO/include/<a class="el" href="vk__mem__alloc_8h.html">vk_mem_alloc.h</a></li>
</ul>
diff --git a/include/vk_mem_alloc.h b/include/vk_mem_alloc.h
index c210ef7..84e6414 100644
--- a/include/vk_mem_alloc.h
+++ b/include/vk_mem_alloc.h
@@ -833,6 +833,8 @@
\brief Represents single memory allocation done inside VmaVirtualBlock.
Use it as a unique identifier to virtual allocation within the single block.
+
+Use value `VK_NULL_HANDLE` to represent a null/invalid allocation.
*/
VK_DEFINE_NON_DISPATCHABLE_HANDLE(VmaVirtualAllocation);
@@ -2382,6 +2384,8 @@
VkDeviceSize* VMA_NULLABLE pOffset);
/** \brief Frees virtual allocation inside given #VmaVirtualBlock.
+
+It is correct to call this function with `allocation == VK_NULL_HANDLE` - it does nothing.
*/
VMA_CALL_PRE void VMA_CALL_POST vmaVirtualFree(
VmaVirtualBlock VMA_NOT_NULL virtualBlock,
@@ -6572,7 +6576,7 @@
{
if (!IsVirtual())
{
- VMA_VALIDATE((VkDeviceSize)alloc->GetAllocHandle() == subAlloc.offset);
+ VMA_VALIDATE((VkDeviceSize)alloc->GetAllocHandle() == subAlloc.offset + 1);
VMA_VALIDATE(alloc->GetSize() == subAlloc.size);
}
@@ -7435,7 +7439,7 @@
{
if (!IsVirtual())
{
- VMA_VALIDATE((VkDeviceSize)alloc->GetAllocHandle() == suballoc.offset);
+ VMA_VALIDATE((VkDeviceSize)alloc->GetAllocHandle() == suballoc.offset + 1);
VMA_VALIDATE(alloc->GetSize() == suballoc.size);
}
sumUsedSize += suballoc.size;
@@ -7477,7 +7481,7 @@
{
if (!IsVirtual())
{
- VMA_VALIDATE((VkDeviceSize)alloc->GetAllocHandle() == suballoc.offset);
+ VMA_VALIDATE((VkDeviceSize)alloc->GetAllocHandle() == suballoc.offset + 1);
VMA_VALIDATE(alloc->GetSize() == suballoc.size);
}
sumUsedSize += suballoc.size;
@@ -7511,7 +7515,7 @@
{
if (!IsVirtual())
{
- VMA_VALIDATE((VkDeviceSize)alloc->GetAllocHandle() == suballoc.offset);
+ VMA_VALIDATE((VkDeviceSize)alloc->GetAllocHandle() == suballoc.offset + 1);
VMA_VALIDATE(alloc->GetSize() == suballoc.size);
}
sumUsedSize += suballoc.size;
@@ -17847,7 +17851,7 @@
VMA_CALL_PRE void VMA_CALL_POST vmaVirtualFree(VmaVirtualBlock VMA_NOT_NULL virtualBlock, VmaVirtualAllocation allocation)
{
- if(virtualBlock != VMA_NULL)
+ if(allocation != VK_NULL_HANDLE)
{
VMA_ASSERT(virtualBlock != VK_NULL_HANDLE);
VMA_DEBUG_LOG("vmaVirtualFree");
diff --git a/src/Tests.cpp b/src/Tests.cpp
index 99e6dc8..843fe1d 100644
--- a/src/Tests.cpp
+++ b/src/Tests.cpp
@@ -2799,6 +2799,9 @@
vmaVirtualFree(block, allocation0);
+ // # Test free of null allocation.
+ vmaVirtualFree(block, VK_NULL_HANDLE);
+
// # Test alignment
{