Vulkan-docs: VK_NULL_HANDLE MSVC Compilation error with v1.2.175 headers (vulkan_core.h)

Created on 14 Apr 2021  路  8Comments  路  Source: KhronosGroup/Vulkan-Docs

I'm using VK_NULL_HANDLE for almost all Vulkan structure pointers but as of updating to the latest headers, I can't compile my app on MSVC anymore.

For example, for the code below:

VkRenderpass renderpass = VK_NULL_HANDLE;

I'm getting an error where it says it can't initialize the variable with an incompatible type (void*).
This is due to MSVC's __cplusplus macro being stuck on C++98 for decades. A correct fix for this would be updating the corresponding macro check like this:

        //#if __cplusplus >= 201103L
        #if __cplusplus >= 201103L || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201103L))
            #define VK_NULL_HANDLE nullptr
        #else
            #define VK_NULL_HANDLE ((void*)0)
        #endif

Most helpful comment

@oddhack Yes, it works just fine. That's identical to what I've done in my project. I hope the fix gets upstream so I don't have to manually patch the header for each release.

It should be going out on Monday or Tuesday at latest.

All 8 comments

The VK_NULL_HANDLE is for non-dispatchable handles only; VkInstance is a dispatchable handle. You can use either NULL or nullptr for dispatchable handles.

@polarina Using VkInstance was merely an example actually, I've edited it but my point still stands. Many codebases rely on VK_NULL_HANDLE, not just mine, and this is a somewhat breaking change (without the proposed fix).

Thanks. We will push out an update to Vulkan-Headers for the MSVC issue shortly, but recommend falling back to the previous headers (or the headers that came with your SDK) in the meantime.

@ifarbod (and anyone else affected), could you test the attached header (which should be identical to your proposed fix) and report back?

vulkan_core.zip

@oddhack Yes, it works just fine. That's identical to what I've done in my project. I hope the fix gets upstream so I don't have to manually patch the header for each release.

@oddhack Yes, it works just fine. That's identical to what I've done in my project. I hope the fix gets upstream so I don't have to manually patch the header for each release.

It should be going out on Monday or Tuesday at latest.

This should be fixed in the 1.2.176 update.

Was this page helpful?
0 / 5 - 0 ratings