#[Solved] WGPU Native Example Segfault

1 messages · Page 1 of 1 (latest)

vestal geyser
#

When running the example, the triangle loads for a single frame and then promptly fails with the following backtrace:

#0  0x00007fffe8608b47 in ?? ()
   from /nix/store/hl2snw5fk954ylsyw1qpznjdpincrh6p-nvidia-x11-555.58.02-nixGL/lib/libnvidia-glcore.so.555.58.02
#1  0x00007fffe89e7a39 in ?? ()
   from /nix/store/hl2snw5fk954ylsyw1qpznjdpincrh6p-nvidia-x11-555.58.02-nixGL/lib/libnvidia-glcore.so.555.58.02
#2  0x00007fffe89ff150 in ?? ()
   from /nix/store/hl2snw5fk954ylsyw1qpznjdpincrh6p-nvidia-x11-555.58.02-nixGL/lib/libnvidia-glcore.so.555.58.02
#3  0x00007fffe893b7ae in ?? ()
   from /nix/store/hl2snw5fk954ylsyw1qpznjdpincrh6p-nvidia-x11-555.58.02-nixGL/lib/libnvidia-glcore.so.555.58.02
#4  0x000000000064a37d in wgpu_hal::vulkan::instance::<impl wgpu_hal::Surface<wgpu_hal::vulkan::Api> for wgpu_hal::vul
kan::Surface>::acquire_texture ()
#5  0x000000000096c3ff in wgpu_core::present::<impl wgpu_core::global::Global<G>>::surface_get_current_texture ()
#6  0x000000000049ee67 in wgpuSurfaceGetCurrentTexture ()
#7  0x0000000000468d85 in wgpu.SurfaceGetCurrentTexture (surface=0x10814a0 "\020\301\006\001")
    at /home/haydengray/Odin/vendor/wgpu/wgpu.odin:1636
#8  0x00000000004461b3 in vendor_wgpu_example_triangle.frame (dt=7.77399982e-05) at main.odin:131
#9  0x00000000004400c7 in vendor_wgpu_example_triangle.os_run (
    os=0xc1d980 <vendor_wgpu_example_triangle.state-795+112>) at os_glfw.odin:32
#10 0x0000000000473a7f in vendor_wgpu_example_triangle.main.on_device-1 (status=Success, 
    device=0x1708620 "\020\301\006\001", message=0x1702500 "", userdata=0x0) at main.odin:117
#11 0x000000000048aeae in wgpuAdapterRequestDevice ()
#12 0x0000000000473210 in vendor_wgpu_example_triangle.main.on_adapter-0 (status=Success, 
    adapter=0x136ab90 "\020\301\006\001", message=0x106fc70 "", userdata=0x0) at main.odin:46
#13 0x000000000049ad90 in wgpuInstanceRequestAdapter ()
#14 0x000000000044042b in vendor_wgpu_example_triangle.main () at main.odin:38
#15 0x00000000004425d5 in main (argc=1, argv=0x7fffffffd7d8) at /home/haydengray/Odin/base/runtime/entry_unix.odin:54

I have tried with both system (Fedora 40) and NixGL graphics libraries, and the July release and master and get the same issue regardless of any of the four configurations I use. Is this something that is an issue with the vendor library or my local driver configuration?
(edited logs to add debug info)

#

another thing to note is that things work when using the official WGPU examples from Rust so i doubt it's a driver thing

echo flare
#

Note that the rust wgpu crate is currently a version ahead, so this might be a bug fixed in that version

vestal geyser
#

the C equivalent runs when checking out the v0.19.4.1 tag

#

i'll try a release build as well

echo flare
#

Thanks for trying

echo flare
vestal geyser
#

yeah, even crashes when i build on my machine and copy over the libraries

vestal geyser
echo flare
#

I have tested this on PopOS and Ubuntu myself and everything works there

#

Also Nvidia/x11

vestal geyser
#

interesting, i'm nvidia/wayland

echo flare
#

Really? I see x11 in your stack trace

vestal geyser
#

oh, it's probably because glfw uses xwayland

#

so yeah, wouldn't matter

#

yeah, i get the x11 indicator in my status bar before it crashes

echo flare
#

What if you build with -define:WGPU_GLFW_GLUE_SUPPORT_WAYLAND=true

vestal geyser
#

nvm

#
/usr/bin/ld: /home/haydengray/Odin/vendor/wgpu/example/example.o: in function `wgpu_glfw_glue.GetSurface':
odin_package:(.text+0x16fa): undefined reference to `glfwGetPlatform'
/usr/bin/ld: odin_package:(.text+0x1711): undefined reference to `glfwGetWaylandDisplay'
/usr/bin/ld: odin_package:(.text+0x1723): undefined reference to `glfwGetWaylandWindow'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
#

i do have wayland-devel and glfw-devel installed

#

and the native c example does run with wayland

echo flare
#

glfw has to be built with -DGLFW_EXPOSE_NATIVE_WAYLAND to have those symbols

#

I think the difference here is that the native c example is also compiling glfw and we are just linking to the system glfw library

vestal geyser
#

ah gotcha

#

so i should probably replace the vendored glfw

echo flare
#

I think that would be the way to go

#

Wondering how we can improve this

vestal geyser
#

i don't think they're building glfw

#

i can't find any references to it in the source

#

*the build that is

#

vnm

#

nvm

#

i can't read

#

quick question, doesn't linux link system glfw?

echo flare
#

On Odin's side? yes

#

Just does -lglfw

vestal geyser
#

also manually compiling glfw and updating the import like so:
foreign import glfw "../lib/libglfw3.a" works

#

*i know that isn't portable

echo flare
#

So the example runs correctly now?

vestal geyser
#

yes

echo flare
#

Even without the -define:WGPU_GL....

#

?

vestal geyser
#

oh, i have to run that too

#

*i run that too

#

odin build . -define:WGPU_GFLW_GLUE_SUPPORT_WAYLAND=true

echo flare
#

ok so compiled glfw yourself and adding that define makes it work, good to know

#

I may add it to the readme there

vestal geyser
#

yes, and of course updating the import to use the new lib

#

which does require modifying vendor:glfw

echo flare
#

Yeah it an ugly fix

vestal geyser
#

yeah, for the short-term a note is better than nothing tho

echo flare
#

It is weird that your glfw-devel doesn't enable wayland though

vestal geyser
#

yeah, i might look into that

echo flare
#

Maybe we should bundle our own glfw library for linux too, but that is always hairy with portability

vestal geyser
#

yeah, i would be careful with that

echo flare
#

And we could do away with needing that -define if we had weak linking that would detect if the wayland symbols are available, but we don't have that currently

vestal geyser
#

yeah, that would be nice in the future

#

also, apparently glfw got wayland with 3.4, fedora is on 3.3.8-6

#

nixpkgs is on 3.4, it ironically would likely work if i just wrote a flake

echo flare
#

Ah so maybe when they ship glfw 3.4 you would only need to add that -define for it all to work

vestal geyser
#

i believe so

#

but it would probably be an issue on debian (if you're on wayland) for a while

echo flare
#

Yep

vestal geyser
#

[Solved] WGPU Native Example Segfault

#

marking as solved since we know what the issue is now

echo flare
#

Yep, thanks for working it out, I will at least add a note to the readme for the time being

vestal geyser
#

Thanks for your help!

echo flare
#

BTW, does (instead of changing the import in glfw bindings), providing -extra-linker-flags:"-L/path/to/your/custom/glfw/build" work?

vestal geyser
#

unfortunately no

#

also the define in glue_linux.odin should be WGPU_GLFW_GLUE_SUPPORT not WGPU_GFLW_GLUE_SUPPORT (just a typo)

echo flare
#

ah right, will correct that

echo flare
#

I can actually get rid of the define because it turns out we do have weak linking

vestal geyser
#

yep, works without the flag now

#

ofc still need to have my custom glfw

echo flare
#

Great thanks

echo flare
vestal geyser
#

yeah, i figured that

#

might just be best to put a note about it and say it'll be fixed when glfw 3.4 is out

echo flare
#

I did update the readme in the pr too

vestal geyser
#

gotcha, saw that

echo flare
#

I would have expected a different error than a segfault deep inside your driver too though

vestal geyser
#

yeah, that was odd

#

esp since i did get one frame

echo flare
#

Yeah even weirder

vestal geyser
#

i mean right now my system is half fedora half nix but even so, i ran it without the nix stuff and it wasn't an issue

#

*fedora base but uses nixGL for some things

#

what nvidia driver are you on? 555?

echo flare
#

No clue, just turned it off too 😆

vestal geyser
#

well, just reloaded into x11 and that worked

#

without new glfw

#

so i would say debian is safe for the time being