1

I have classes who handle (Vulkan) ressources, lets call them VulkanInstance and VulkanDevice. My Master class owns both of these

class Master {
    VulkanInstance instance_;
    VulkanDevice device_;
    reset();
}

in my reset function i want to delete the current instance and device and create a new one. I thought of the following conditions:

  1. device_ must be destroyed before instace_ can be destroyed, because device_ depends on instance_
  2. instance_ must be created before device_ can be created
  3. device_ and instance_ can't be copied, however they can be constructed, move contructed and move assigned
  4. i want to create a new VulkanInstance and VulkanDevice before deleting the old instance_ and device_. So that when i get errors during construction of the new elements i still have the old valid classes left.

My question is: How should i design the reset function. Can it be realised without using pointers / std::unique_ptr to VulkanInstance or VulkanDevice.

I though about something like this

 // PSEUDO CODE
 Master::reset() {
     VulkanInstance new_instance {};
     VulkanDevice new_device {};
     device_ = new_device; //use move here and destruct old device_ Dont use copy constructor
     instance_ = new_instance; //use move here and destruct old device_ Dont use copy constructor
 }
mac.1
  • 100
  • 5

0 Answers0