Closed gaultier closed 10 months ago
Looks like the procedure pointers aren't being loaded, therefore on the first call to vk.CreateInstance
it tries to call a null-pointer which results in a SIGSEGV.
You should try passing the pointer returned by SDL_Vulkan_GetVkGetInstanceProcAddr
to vk.load_proc_address_global
. Read the documentation on the SDL proc though, seems like there's one more set up step you need to do before you call that function.
My guess is that the difference comes from the fact that C headers contained the function pointers, which we're not calling into and somehow the wrong function pointers are being initialized. This is not a bug with the vulkan
vendor package.
Thank you, that fixed it!
diff --git a/main.odin b/main.odin
index a30dcb4..c413dcd 100644
--- a/main.odin
+++ b/main.odin
@@ -1,5 +1,6 @@
package main
+import "core:fmt"
import "core:os"
import "vendor:sdl2"
import "vendor:vulkan"
@@ -13,6 +14,13 @@ main :: proc() {
if window == nil {
os.exit(1)
}
+
+ getInstanceProcAddr := sdl2.Vulkan_GetVkGetInstanceProcAddr()
+ assert(getInstanceProcAddr != nil)
+
+ vulkan.load_proc_addresses_global(getInstanceProcAddr)
+ assert(vulkan.CreateInstance != nil)
+
app_info: vulkan.ApplicationInfo = {
sType = .APPLICATION_INFO,
applicationVersion = vulkan.MAKE_VERSION(0, 0, 1),
@@ -28,4 +36,5 @@ main :: proc() {
if r := vulkan.CreateInstance(&create_info, nil, &instance); r != .SUCCESS {
os.exit(1)
}
+ fmt.println("instance created")
}
So the function pointers need to be loaded manually. Not sure if that should be mentioned in the docs?
By the way you can use ```diff to highlight diffs in color
Regarding docs, maybe yeah, they kinda suck currently
Context
Using Wayland (swaywm).
Expected Behavior
I am creating a window with the
vendor:sdl2
package (which works fine) and a vulkan instance with thevendor:vulkan
package. I expect it to run fine but it segfaults.Current Behavior
It segfaults on the first vulkan call, whatever it is.
Failure Information (for bugs)
GDB only shows that the segfault happens within the vulkan call:
Steps to Reproduce
This segfaults. Interestingly, any vulkan call will segfault, not just CreateInstance.
E.g.:
Will also segfault.
The equivalent C code runs fine (same machine, same SDL/Vulkan version) and prints
instance created
as expected:I tried to:
libvulkan.so
is not explicitly linked and isdlopen
-ed at runtime,libvulkan.so
at compile time so:odin build . -debug -o:none -extra-linker-flags='-lvulkan'
. Both result in the same segfault. Even thoughldd
for the C program and for the Odin program has the same output (same libraries linked, same versions, paths, etc).Failure Logs
UPDATE: Tried the same code on a different machine (Ubuntu 23.04 as well, but with a Nvidia GPU): same outcome. The Odin code segfaults, the C code works.