简体   繁体   中英

How to properly clean Vulkan objects?

Do VkObjects need to be nulled, or is it solved somehow in automatic way?

  • For example when I have Buffer class which is wrapper for
VkBuffer _buffer;

and destructor like this:

Buffer::~Buffer()
{
  vkDestroyBuffer(_device.getLogicalDevice(), _buffer, nullptr);
  if(_memory) {
    vkFreeMemory(_device.getLogicalDevice(), _memory, nullptr);
  }
}

Do I need to set, after destructor is called, _buffer to VK_NULL_HANDLE or nullptr or it is not necessary and this is done in automatic way?

(Basically what is my question is if specification stands in which state is left the object instance after calling vkDestroyXYZ / vkFreeXYZ)

And if yes, it applies for all VkObjects (like VkInstance , VkImage , etc.) or there are some exceptions?

I thought I am pretty OK if I left the object as it is (especially when it is immediately destroyed after), but we come to this discussion during the code review and lets say, that my reviewer has set -pedantic and -Wall for the sake of our code base I must admit :)

When you have (properly) destroyed a Vulkan object, it is destroyed. That's the end of it. It's no different from destroying an object in C++ through its pointer: the object being pointed to is gone .

What you do with the pointer value itself is up to you (outside of passing its value as input to Vulkan APIs, which of course you can't do).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM