Acces violation when defining an array on stack


An odd error appears after a function call if an array of VkQueueFamilyProperties is defined on a stack instead of on the heap. I do not understand why this would happen since the variable is in no way related to the given function call.

I have the following code:

#include <stdlib.h>
#include <vulkan/vulkan.h>
#include <stdio.h>
#include <GLFW/glfw3.h>

GLFWwindow* window;

void main(){
    glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);

    window = glfwCreateWindow(1280, 720, "tArh", 0, 0);

    VkInstance instance;

    VkApplicationInfo info;
    info.pApplicationName = "tArh";
    info.applicationVersion = VK_MAKE_VERSION(0, 0, 1);
    info.pEngineName = "Tarh";
    info.engineVersion = VK_MAKE_VERSION(0, 0, 1);
    info.apiVersion = VK_API_VERSION_1_0;

    VkInstanceCreateInfo cinfo;
    cinfo.pApplicationInfo = &info;
    cinfo.enabledLayerCount = 0;
    cinfo.enabledExtensionCount = 0;
    cinfo.ppEnabledExtensionNames = 0;

    //ERROR OCCURS AFTER THIS LINE IF props[2] is defined below
    //The code after this line does not get executed
    int fail = vkCreateInstance(&cinfo, 0, &instance);

        printf("Vulkan Failed\n");

    VkPhysicalDevice device = 0;
    uint count = 1;

    //Works fine
    // VkQueueFamilyProperties* props = (VkQueueFamilyProperties*) malloc(sizeof(VkQueueFamilyProperties) * 2);

    //Causes an error to occur at vkCreateInstance
    VkQueueFamilyProperties props[2];

    //Needs to be defined for the error to occur
    vkGetPhysicalDeviceQueueFamilyProperties(device, &count, props);

It is build using CL on windows for x64 architectures using the following build script

$SOURCES = ls src -Recurse -Filter *.cpp | % { $_.FullName}

cl /Zi /EHsc `
/Fe: build\\window.exe `
/Fo: build\\ `
/Fd: build\\vc140.pdb `
/FI arh\arh.h `
/I C:\Users\Demi\Desktop\Files\Installs\vcpkg\installed\x64-windows\include `
/I C:\Users\Demi\Desktop\Files\Installs\imgui `
/I "C:\VulkanSDK\\Include" `
/I ./inc `
vulkan-1.lib `
glfw3dll.lib `
/link `
/LIBPATH:"C:\Users\Demi\Desktop\Files\Installs\vcpkg\installed\x64-windows\lib" `

The following error appears right after the call to vkCreateInstance after which the debugger halts and no more code is executed.

Exception has occurred: W32/0xc0000005
Unhandled exception at 0x00007FFDD6ACD240 (vulkan-1.dll) in window.exe: 0xC0000005: Access violation reading location 0x00000000FFFFFFFF.

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0