Hitokage
Hitokage

Reputation: 803

Using Vulkan unique handle in struct leads to "implicitly deleted" error

I have this in my code:

struct Buffer
        {
            vk::UniqueBuffer buffer;
            vk::UniqueDeviceMemory memory;
            unsigned int top{0};
        };

        struct Image
        {
            vk::UniqueImage textureImage;
            vk::UniqueDeviceMemory textureImageMemory;
        };

        struct Texture
        {
            Image image;
            vk::UniqueImageView imageView;
            vk::UniqueSampler sampler;
        };

        struct SwapChainFrame
        {
            vk::Image image;
            vk::UniqueImageView imageView;
            vk::UniqueFramebuffer frameBuffer;
            vk::UniqueCommandBuffer commandBuffer;
            Buffer uniformVpMatrix;
            vk::UniqueDescriptorSet descriptorSet;
        };

Storing unique handles in Vulkan worked well till I added the Image and Texture ones. Now I'm getting this:

   In file included from .../gpuVulkan.h:50:16: note: ‘GpuVulkan::Texture::Texture(const GpuVulkan::Texture&)’ is implicitly deleted because the default definition would be ill-formed:
             struct Texture
                    ^~~~~~~
    .../gpuVulkan.h:50:16: error: use of deleted function ‘GpuVulkan::Image::Image(const GpuVulkan::Image&)’
    .../gpuVulkan.h:44:16: note: ‘GpuVulkan::Image::Image(const GpuVulkan::Image&)’ is implicitly deleted because the default definition would be ill-formed:
             struct Image
                    ^~~~~
    .../gpuVulkan.h:44:16: error: use of deleted function ‘vk::UniqueHandle<Type, Dispatch>::UniqueHandle(const vk::UniqueHandle<Type, Dispatch>&) [with Type = vk::Image; Dispatch = vk::DispatchLoaderStatic]’
    In file included from .../gpuVulkan.h:1,
                     from .../src/gpuVulkan.cpp:5:
    /usr/include/vulkan/vulkan.hpp:392:5: note: declared here
         UniqueHandle( UniqueHandle const& ) = delete;
         ^~~~~~~~~~~~
    In file included from ...gpuVulkan.cpp:5:
    .../gpuVulkan.h:44:16: error: use of deleted function ‘vk::UniqueHandle<Type, Dispatch>::UniqueHandle(const vk::UniqueHandle<Type, Dispatch>&) [with Type = vk::DeviceMemory; Dispatch = vk::DispatchLoaderStatic]’
             struct Image

Any ideas what's wrong? The Buffer and SwapChainFrame works well. Seems like a similar issue was reported here but I'm not sure if this is the same problem. Any help would be much appreciated! Thanks

Upvotes: 0

Views: 565

Answers (1)

Your Image class doesn't have a copy constructor (because vk::UniqueImage doesn't have a copy constructor). That means Texture doesn't have a copy constructor either.

The other classes don't have a copy constructor either, but that's OK unless you try to copy them. (In this case, from the comments, by creating a std::vector<Texture>.)

Upvotes: 3

Related Questions