mach icon indicating copy to clipboard operation
mach copied to clipboard

Core: triangle example crashes at runtime on wayland with segmentation fault.

Open nilsj2 opened this issue 1 year ago • 11 comments

> ~/zig/0.13.0-dev.351+64ef45eb0/files/zig build run-triangle
Segmentation fault at address 0x40
???:?:?: 0x7f2b2d690700 in ??? (libwayland-client.so.0)
Unwind information for `libwayland-client.so.0:0x7f2b2d690700` was not available, trace may be incomplete

/home/nilsj/Projects/zfps/libs/mach/src/core/linux/Wayland.zig:158:76: 0x10c7e2a in init (core-triangle)
    const decoration = c.zxdg_decoration_manager_v1_get_toplevel_decoration(
                                                                           ^
/home/nilsj/Projects/zfps/libs/mach/src/core/Linux.zig:94:41: 0x10c9272 in init (core-triangle)
            const wayland = Wayland.init(linux, core, options) catch |err| switch (err) {
                                        ^
/home/nilsj/Projects/zfps/libs/mach/src/Core.zig:210:22: 0x10dd47e in init (core-triangle)
    try Platform.init(&state.platform, core, options);
                     ^
/home/nilsj/Projects/zfps/libs/mach/src/module/module.zig:444:32: 0x113ae10 in dispatchInternal__anon_13063 (core-triangle)
                .ErrorUnion => try @call(.auto, handler, args),
                               ^
/home/nilsj/Projects/zfps/libs/mach/src/module/module.zig:360:38: 0x113c74f in dispatch (core-triangle)
            return m.dispatchInternal(stack_space, options, injectable);
                                     ^
/home/nilsj/Projects/zfps/libs/mach/examples/core/triangle/main.zig:23:27: 0x113c89e in main (core-triangle)
    try mach.mods.dispatch(stack_space, .{});
                          ^
/home/nilsj/zig/0.13.0-dev.351+64ef45eb0/files/lib/std/start.zig:524:37: 0x113ccde in main (core-triangle)
            const result = root.main() catch |err| {
                                    ^
run-triangle
└─ run core-triangle failure
error: the following command terminated unexpectedly:
/home/nilsj/Projects/zfps/libs/mach/zig-out/bin/core-triangle
Build Summary: 53/55 steps succeeded; 1 failed (disable with --summary none)
run-triangle transitive failure
└─ run core-triangle failure
error: the following build command failed with exit code 1:
/home/nilsj/Projects/zfps/libs/mach/.zig-cache/o/7cfc9a16a152f450c50d3b7c363cfb8b/build /home/nilsj/zig/0.13.0-dev.351+64ef45eb0/files/zig /home/nilsj/Projects/zfps/libs/mach /home/nilsj/Projects/zfps/libs/mach/.zig-cache /home/nilsj/.cache/zig --seed 0x7c877ff2 -Z24801e53fa41fc62 run-triangle

nilsj2 avatar Oct 01 '24 20:10 nilsj2

@nippi05 Would you be able to confirm that https://github.com/hexops/mach/pull/1289 fixes this issue?

ronald-mz avatar Oct 21 '24 17:10 ronald-mz

@RonaldZielaznicki I'm still getting the same error 😕

nilsj2 avatar Oct 21 '24 19:10 nilsj2

@nippi05

Hrrrm. And just to cover the bases, this is while running the latest main? Or are you running 4.0?

ronald-mz avatar Oct 21 '24 19:10 ronald-mz

@RonaldZielaznicki yes master.

nilsj2 avatar Oct 21 '24 19:10 nilsj2

which compositor are you using? also try running it with WAYLAND_DEBUG=1 as an environment variable another thing is you're running 0.13.0-dev.351+64ef45eb0, try the mach nominated zig version

dysphoriac avatar Oct 22 '24 01:10 dysphoriac

It's gnome so Mutter(?). I'm using mach nominated version here is output with WAYLAND_DEBUG=1:

~/Projects/zfps/libs/mach main 29s ❯ zig version           
0.14.0-dev.1911+3bf89f55c
~/Projects/zfps/libs/mach main ❯ WAYLAND_DEBUG=1 zig build run-triangle
[1642744.646]  -> [email protected]_registry(new id wl_registry@2)
[1642744.660]  -> [email protected](new id wl_callback@3)
[1642744.807] [email protected]_id(3)
[1642744.819] [email protected](1, "wl_compositor", 5)
[1642744.831]  -> [email protected](1, "wl_compositor", 3, new id [unknown]@4)
[1642744.840] [email protected](2, "wl_drm", 2)
[1642744.847] [email protected](3, "wl_shm", 1)
[1642744.856]  -> [email protected](3, "wl_shm", 1, new id [unknown]@5)
[1642744.864] [email protected](4, "wl_output", 3)
[1642744.872]  -> [email protected](4, "wl_output", 3, new id [unknown]@6)
[1642744.880] [email protected](5, "zxdg_output_manager_v1", 3)
[1642744.886] [email protected](6, "wl_data_device_manager", 3)
[1642744.893] [email protected](7, "zwp_primary_selection_device_manager_v1", 1)
[1642744.902] [email protected](8, "wl_subcompositor", 1)
[1642744.910]  -> [email protected](8, "wl_subcompositor", 1, new id [unknown]@7)
[1642744.915] [email protected](9, "xdg_wm_base", 4)
[1642744.926]  -> [email protected](9, "xdg_wm_base", 3, new id [unknown]@8)
[1642744.932] [email protected](10, "gtk_shell1", 5)
[1642744.938] [email protected](11, "wp_viewporter", 1)
[1642744.945] [email protected](12, "zwp_pointer_gestures_v1", 3)
[1642744.951] [email protected](13, "zwp_tablet_manager_v2", 1)
[1642744.956] [email protected](14, "wl_seat", 8)
[1642744.963]  -> [email protected](14, "wl_seat", 3, new id [unknown]@9)
[1642744.969] [email protected](15, "zwp_relative_pointer_manager_v1", 1)
[1642744.976] [email protected](16, "zwp_pointer_constraints_v1", 1)
[1642744.982] [email protected](17, "zxdg_exporter_v1", 1)
[1642744.988] [email protected](18, "zxdg_importer_v1", 1)
[1642744.994] [email protected](19, "zwp_linux_dmabuf_v1", 4)
[1642745.000] [email protected](20, "wp_single_pixel_buffer_manager_v1", 1)
[1642745.006] [email protected](21, "zwp_keyboard_shortcuts_inhibit_manager_v1", 1)
[1642745.013] [email protected](22, "zwp_text_input_manager_v3", 1)
[1642745.019] [email protected](23, "wp_presentation", 1)
[1642745.025] [email protected](24, "xdg_activation_v1", 1)
[1642745.031] [email protected](3082)
[1642745.038]  -> [email protected](new id wl_callback@3)
[1642745.139] [email protected]_id(3)
[1642745.151] [email protected](3)
[1642745.158]  -> [email protected]_keyboard(new id wl_keyboard@10)
[1642745.166]  -> [email protected]_pointer(new id wl_pointer@11)
[1642745.172] [email protected]("seat0")
[1642745.178] [email protected](3082)
[1642745.184]  -> [email protected]_surface(new id wl_surface@3)
[1642745.191]  -> [email protected]_region(new id wl_region@12)
[1642745.198]  -> [email protected](0, 0, 960, 540)
[1642745.204]  -> [email protected]_opaque_region(wl_region@12)
[1642745.210]  -> [email protected]()
[1642745.217]  -> [email protected]_xdg_surface(new id xdg_surface@13, wl_surface@3)
[1642745.228]  -> [email protected]_toplevel(new id xdg_toplevel@14)
[1642745.234]  -> [email protected]()
[1642747.342] [email protected]_id(12)
[1642747.359] [email protected](1, fd 4, 76270)
[1642754.533] [email protected](0, 0, array[0])
[1642754.548] [email protected](115)
[1642754.556]  -> [email protected]_configure(115)
[1642754.564]  -> [email protected]_region(new id wl_region@12)
[1642754.570]  -> [email protected](0, 0, 960, 540)
[1642754.577]  -> [email protected]_opaque_region(wl_region@12)
[1642754.582]  -> [email protected]()
[1642754.589]  -> [email protected]_title("Mach core")
Segmentation fault at address 0x40
???:?:?: 0x7ff519746700 in ??? (libwayland-client.so.0)
Unwind information for `libwayland-client.so.0:0x7ff519746700` was not available, trace may be incomplete

/home/nilsj/Projects/zfps/libs/mach/src/core/linux/Wayland.zig:158:76: 0x10f2273 in init (core-triangle)
    const decoration = c.zxdg_decoration_manager_v1_get_toplevel_decoration(
                                                                           ^
/home/nilsj/Projects/zfps/libs/mach/src/core/Linux.zig:104:41: 0x10f3f58 in init (core-triangle)
            const wayland = Wayland.init(linux, core, options) catch |err| {
                                        ^
/home/nilsj/Projects/zfps/libs/mach/src/Core.zig:210:22: 0x110833e in init (core-triangle)
    try Platform.init(&state.platform, core, options);
                     ^
/home/nilsj/Projects/zfps/libs/mach/src/module/module.zig:444:33: 0x116a112 in dispatchInternal__anon_10183 (core-triangle)
                .error_union => try @call(.auto, handler, args),
                                ^
/home/nilsj/Projects/zfps/libs/mach/src/module/module.zig:360:38: 0x116b89f in dispatch (core-triangle)
            return m.dispatchInternal(stack_space, options, injectable);
                                     ^
/home/nilsj/Projects/zfps/libs/mach/examples/core/triangle/main.zig:23:27: 0x116b9ee in main (core-triangle)
    try mach.mods.dispatch(stack_space, .{});
                          ^
/home/nilsj/zig/0.14.0-dev.1911+3bf89f55c/files/lib/std/start.zig:621:37: 0x116be2e in main (core-triangle)
            const result = root.main() catch |err| {
                                    ^
run-triangle
└─ run core-triangle failure
error: the following command terminated unexpectedly:
/home/nilsj/Projects/zfps/libs/mach/zig-out/bin/core-triangle 
Build Summary: 44/46 steps succeeded; 1 failed
run-triangle transitive failure
└─ run core-triangle failure
error: the following build command failed with exit code 1:
/home/nilsj/Projects/zfps/libs/mach/.zig-cache/o/aace89b9cb039f7ed7d7b50486356fc2/build /home/nilsj/zig/0.14.0-dev.1911+3bf89f55c/files/zig /home/nilsj/zig/0.14.0-dev.1911+3bf89f55c/files/lib /home/nilsj/Projects/zfps/libs/mach /home/nilsj/Projects/zfps/libs/mach/.zig-cache /home/nilsj/.cache/zig --seed 0x984f4825 -Zcccc9b2d2b473923 run-triangle

nilsj2 avatar Oct 22 '24 08:10 nilsj2

it looks like its trying to set the decoration mode using the xdg-decoration protocol but that protocol is not implemented by mutter, so its just trying to access a out of bounds memory address, and it segfaults.

unfortunately unless gnome implements the protocol and provides server side decoration, which is unlikely , mach might have to provide some sort of client side decoration in order to work on fully gnome

these are basically the options:

  1. add csd to mach.

undesirable for mach devs, would probably mean adding libdecor or something like that

  1. add ssd to mutter

undesirable for gnome devs, unlikely due to philosophical differences

  1. just add something that disables the checks if the zxdg_decoration_manager_v1 exists before calling c.zxdg_decoration_manager_v1_get_toplevel_decoration()

would break window moving and resizing, kinda hacky, undesirable for everyone

dysphoriac avatar Oct 22 '24 13:10 dysphoriac

Thank you for the insight dysphoriac. And ain't that just frustrating, looks like we're betweeen a rock and a hard place here. Checked in on the docs for the protocol, and they've a helpful graphic.

image

@slimsag Mind if I ask your opinion on what direction we'd like to go?

ronald-mz avatar Oct 22 '24 16:10 ronald-mz

I believe that GLFW also uses libdecor by default, falling back to SSD only if libdecor is not found.

I think we should do the same here. And, obviously, we should std.DynLib the dependency on libdecor and not rely on system headers for compilation so that cross compilation works.

If libdecor is not available, we should fallback to SSD. If SSD is not available, then let's exit with an error message telling the user their OS is broken and to install libdecor - rather than e.g. having an unresizable window

emidoots avatar Oct 23 '24 20:10 emidoots

Think as a stopgap, I'll throw up a PR that'll give a proper error if SSD is not supported.

That way we'll stop getting new/similar reports about if while libdecor is hooked up.

ronald-mz avatar Oct 24 '24 04:10 ronald-mz

That sounds perfect

emidoots avatar Oct 24 '24 05:10 emidoots