Mercurial > games > semicongine
diff src/zamikongine/buffer.nim @ 33:94c38e4b5782
did: refactoring, move more from make to nimscript
author | Sam <sam@basx.dev> |
---|---|
date | Sun, 15 Jan 2023 23:23:54 +0700 |
parents | 9edca5dc4e93 |
children |
line wrap: on
line diff
--- a/src/zamikongine/buffer.nim Sat Jan 14 23:34:50 2023 +0700 +++ b/src/zamikongine/buffer.nim Sun Jan 15 23:23:54 2023 +0700 @@ -21,9 +21,11 @@ proc trash*(buffer: var Buffer) = assert int64(buffer.vkBuffer) != 0 - assert int64(buffer.memory) != 0 vkDestroyBuffer(buffer.device, buffer.vkBuffer, nil) buffer.vkBuffer = VkBuffer(0) + if buffer.size == 0: # for zero-size buffers there are no memory allocations + return + assert int64(buffer.memory) != 0 vkFreeMemory(buffer.device, buffer.memory, nil) buffer.memory = VkDeviceMemory(0) @@ -65,7 +67,8 @@ allocationSize: result.memoryRequirements.size, memoryTypeIndex: result.findMemoryType(physicalDevice, VkMemoryPropertyFlags(memoryProperties)) ) - checkVkResult result.device.vkAllocateMemory(addr(allocInfo), nil, addr(result.memory)) + if result.size > 0: + checkVkResult result.device.vkAllocateMemory(addr(allocInfo), nil, addr(result.memory)) checkVkResult result.device.vkBindBufferMemory(result.vkBuffer, result.memory, VkDeviceSize(0)) if persistentMapping: checkVkResult vkMapMemory(