#Dependency setup for Vulkan/SDL2?

1 messages · Page 1 of 1 (latest)

daring coral
#

I'm trying to make an SDL2/Vulkan app in Odin, but I'm having trouble that when trying to create an instance, the application crashes because of reading null reference; I'm not sure why this is happening.

Through some basic google-ing, I found that for SDL, I need SDL2.dll from odin/vendor directory. I got that, but I'm not sure what to do about Vulkan. I have Vulkan SDK installed on the computer, and I confirmed from vsdbg (in VSCode) that vulkan-1.dll library gets loaded, but this doesn't seem to be enough. Here's the code...

    sdl2.Init(sdl2.INIT_VIDEO)

    tempWindow := sdl2.CreateWindow(
        "temp window to get instance extensions",
        0,
        0,
        800,
        600,
        sdl2.WINDOW_VULKAN | sdl2.WINDOW_ALLOW_HIGHDPI | sdl2.WINDOW_SHOWN,
    )
    defer sdl2.DestroyWindow(tempWindow)

    instance: vulkan.Instance = ---
    {
        extensionsCount := u32(0)
        sdl2.Vulkan_GetInstanceExtensions((^sdl2.Window)(tempWindow), &extensionsCount, nil)
        extensions := make([]cstring, extensionsCount)
        defer delete(extensions)
        sdl2.Vulkan_GetInstanceExtensions((^sdl2.Window)(tempWindow), &extensionsCount, raw_data(extensions))

        // print extensions
        for i := u32(0); i < extensionsCount; i += 1 {
            debug.log("Renderer", debug.LogLevel.INFO, string(extensions[i]))
        }

        // create vulkan instance
        appInfo := vulkan.ApplicationInfo {
            // ..
        }

        instanceInfo := vulkan.InstanceCreateInfo {
            // ..
        }

        result := vulkan.CreateInstance(&instanceInfo, nil, &instance) // the line that crashes because of null reference
        if result != vulkan.Result.SUCCESS {
            debug.log("Renderer", debug.LogLevel.ERROR, "Failed to create vulkan instance")
        }
    }
plush wedge
#

Did you get the same sdl2 dll as the odin vendor libraries?

Does it say which line is crashing?

daring coral
#

@plush wedge I don’t get any error when building or linking. The null ref is on the line trying to create vk instance.

river ice
#

The functions will be null until you load them in.

Functions from the vulkan binding:

load_proc_addresses :: proc{
    load_proc_addresses_global,
    load_proc_addresses_instance,
    load_proc_addresses_device,
    load_proc_addresses_device_vtable,
    load_proc_addresses_custom,
}
#

You first call load_proc_addresses_global

#
vk_dll := win32.LoadLibraryW(win32.utf8_to_wstring("vulkan-1.dll"))

get_instance_proc_address := auto_cast win32.GetProcAddress(vk_dll, "vkGetInstanceProcAddr")

if get_instance_proc_address == nil {
    panic("vkGetInstanceProcAddr not loaded")
}
vulkan.load_proc_addresses_global(get_instance_proc_address)
```