Skip to content

Commit e880547

Browse files
authored
Merge pull request #611 from novelrt/bugfix/memory-mapping-assert
Fix memory mapping assert.
2 parents ad8def6 + 82d5683 commit e880547

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

Graphics/Vulkan/VulkanGraphicsBuffer.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace NovelRT::Graphics::Vulkan
2525
VkBuffer vulkanBuffer)
2626
: VulkanGraphicsResource(graphicsDevice, allocator, cpuAccess, allocation, allocationInfo),
2727
_vulkanBuffer(vulkanBuffer),
28-
_subAllocations(0),
28+
_mappedMemoryRegions(0),
2929
_cpuAccess(cpuAccess),
3030
_kind(kind)
3131
{}
@@ -34,8 +34,8 @@ namespace NovelRT::Graphics::Vulkan
3434
{
3535
auto allocator = GetAllocator()->GetVmaAllocator();
3636
auto allocation = GetAllocation();
37-
38-
assert_message("Attempted to destroy a VkBuffer containing mapped regions.", _subAllocations != 0);
37+
38+
assert_message(_mappedMemoryRegions == 0, "Attempted to destroy a VkBuffer containing mapped regions.");
3939

4040
vmaDestroyBuffer(allocator, GetVulkanBuffer(), allocation);
4141
}
@@ -61,7 +61,7 @@ namespace NovelRT::Graphics::Vulkan
6161
throw std::runtime_error("Failed to map Vulkan memory to the CPU. Reason: " + std::to_string(result));
6262
}
6363

64-
_subAllocations++;
64+
_mappedMemoryRegions++;
6565

6666
return Utilities::Misc::Span<uint8_t>(reinterpret_cast<uint8_t*>(data) + rangeOffset, rangeLength);
6767
}
@@ -97,26 +97,26 @@ namespace NovelRT::Graphics::Vulkan
9797
throw std::runtime_error("Failed to invalidate mapped memory. Reason: " + std::to_string(mapResult));
9898
}
9999

100-
_subAllocations++;
100+
_mappedMemoryRegions++;
101101

102102
return Utilities::Misc::Span<const uint8_t>(reinterpret_cast<const uint8_t*>(data), rangeLength);
103103
}
104104

105105
void VulkanGraphicsBuffer::UnmapBytes()
106106
{
107-
if (_subAllocations == 0)
107+
if (_mappedMemoryRegions == 0)
108108
{
109109
throw Exceptions::InvalidOperationException("Attempted to unmap region of buffer when no memory map was created.");
110110
}
111111

112-
_subAllocations--;
112+
_mappedMemoryRegions--;
113113

114114
vmaUnmapMemory(GetAllocator()->GetVmaAllocator(), GetAllocation());
115115
}
116116

117117
void VulkanGraphicsBuffer::UnmapBytesAndWrite(size_t writtenRangeOffset, size_t writtenRangeLength)
118118
{
119-
if (_subAllocations == 0)
119+
if (_mappedMemoryRegions == 0)
120120
{
121121
throw Exceptions::InvalidOperationException("Attempted to unmap region of buffer when no memory map was created.");
122122
}
@@ -141,7 +141,7 @@ namespace NovelRT::Graphics::Vulkan
141141
std::to_string(result));
142142
}
143143

144-
_subAllocations--;
144+
_mappedMemoryRegions--;
145145

146146
vmaUnmapMemory(allocator, allocation);
147147
}

Graphics/Vulkan/VulkanGraphicsTexture.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ namespace NovelRT::Graphics::Vulkan
119119
: VulkanGraphicsResource(device, allocator, cpuAccess, allocation, allocationInfo),
120120
// GraphicsTexture(device, allocator, cpuAccess, addressMode, kind, width, height, depth),
121121
_vulkanImage(vulkanImage),
122-
_subAllocations(0),
122+
_mappedMemoryRegions(0),
123123
_addressMode(addressMode),
124124
_kind(kind),
125125
_vulkanImageView([&]() { return CreateVulkanImageView(); }),
@@ -144,7 +144,7 @@ namespace NovelRT::Graphics::Vulkan
144144
auto allocator = VulkanGraphicsResource::GetAllocator()->GetVmaAllocator();
145145
auto allocation = GetAllocation();
146146

147-
assert_message(_subAllocations != 0, "Attempted to destroy a VkImage containing mapped regions.");
147+
assert_message(_mappedMemoryRegions == 0, "Attempted to destroy a VkImage containing mapped regions.");
148148

149149
if (_vulkanImageView.isCreated())
150150
{
@@ -192,7 +192,7 @@ namespace NovelRT::Graphics::Vulkan
192192
throw std::runtime_error("Failed to map Vulkan memory to the CPU. Reason: " + std::to_string(result));
193193
}
194194

195-
_subAllocations++;
195+
_mappedMemoryRegions++;
196196

197197
return NovelRT::Utilities::Misc::Span<uint8_t>(reinterpret_cast<uint8_t*>(data) + rangeOffset, rangeLength);
198198
}
@@ -229,26 +229,26 @@ namespace NovelRT::Graphics::Vulkan
229229
throw std::runtime_error("Failed to invalidate mapped memory. Reason: " + std::to_string(mapResult));
230230
}
231231

232-
_subAllocations++;
232+
_mappedMemoryRegions++;
233233

234234
return NovelRT::Utilities::Misc::Span<const uint8_t>(reinterpret_cast<const uint8_t*>(data), rangeLength);
235235
}
236236

237237
void VulkanGraphicsTexture::UnmapBytes()
238238
{
239-
if (_subAllocations == 0)
239+
if (_mappedMemoryRegions == 0)
240240
{
241241
throw Exceptions::InvalidOperationException("Attempted to unmap region of texture when no memory map was created.");
242242
}
243243

244-
_subAllocations--;
244+
_mappedMemoryRegions--;
245245

246246
vmaUnmapMemory(VulkanGraphicsResource::GetAllocator()->GetVmaAllocator(), GetAllocation());
247247
}
248248

249249
void VulkanGraphicsTexture::UnmapBytesAndWrite(size_t writtenRangeOffset, size_t writtenRangeLength)
250250
{
251-
if (_subAllocations == 0)
251+
if (_mappedMemoryRegions == 0)
252252
{
253253
throw Exceptions::InvalidOperationException("Attempted to unmap region of texture when no memory map was created.");
254254
}
@@ -273,7 +273,7 @@ namespace NovelRT::Graphics::Vulkan
273273
std::to_string(result));
274274
}
275275

276-
_subAllocations--;
276+
_mappedMemoryRegions--;
277277

278278
vmaUnmapMemory(allocator, allocation);
279279
}

Graphics/Vulkan/include/NovelRT/Graphics/Vulkan/VulkanGraphicsBuffer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace NovelRT::Graphics::Vulkan
2020
{
2121
private:
2222
VkBuffer _vulkanBuffer;
23-
size_t _subAllocations;
23+
size_t _mappedMemoryRegions;
2424
GraphicsResourceAccess _cpuAccess;
2525
GraphicsBufferKind _kind;
2626

Graphics/Vulkan/include/NovelRT/Graphics/Vulkan/VulkanGraphicsTexture.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace NovelRT::Graphics::Vulkan
1616
{
1717
private:
1818
VkImage _vulkanImage;
19-
size_t _subAllocations;
19+
size_t _mappedMemoryRegions;
2020
GraphicsTextureAddressMode _addressMode;
2121
GraphicsTextureKind _kind;
2222

0 commit comments

Comments
 (0)