waylandpp icon indicating copy to clipboard operation
waylandpp copied to clipboard

Something is wrong with `resource_t` in `wayland-server++`

Open twaik opened this issue 2 years ago • 0 comments

I a writing a backend for Xwayland and something is wrong here.

Code
#include <iostream>
#include <cstdio>
#include <wayland-server.hpp>
#include "wayland-server-protocol.hpp"
#include "xdg-shell-protocol.hpp"

using namespace std;
using namespace wayland::server;

int main()
{
    ::remove("/run/user/1000/wayland-0.lock");
    try {
        cout << "Hello World!" << endl;
        display_t display;
        display.add_socket_auto();
        wl_display_init_shm(display.c_ptr());

        global_compositor_t global_compositor(display);
        global_xdg_wm_base_t global_wm_base(display);
        global_output_t global_output(display);
        global_seat_t global_seat(display);

        global_output.on_bind() = [](const client_t& /*client*/, output_t output) {
            output.geometry(0, 0, 270, 158, output_subpixel::unknown, "weston-x11", "none", output_transform::normal);
            output.scale(1);
            output.mode(3, 1024, 600, 60000);
            output.done();
        };
        global_seat.on_bind() = [](const client_t& /*client*/, seat_t seat) {
            seat.on_get_touch() = [](touch_t /*touch*/) {};
            seat.on_get_keyboard() = [](keyboard_t /*kbd*/) {};
            seat.on_get_pointer() = [](pointer_t pointer) {
                pointer.on_set_cursor() = [](uint32_t /*serial*/, surface_t /*surface*/, int32_t /*hotspot_x*/, int32_t /*hotspot_y*/) {};
            };
            seat.capabilities(seat_capability::pointer | seat_capability::keyboard | seat_capability::touch);
        };

        display.run();
    } catch(const std::exception& ex) {
        std::cout << "Error occured: " << ex.what() << std::endl;
    }
    return 0;
}

Header references are relative to sources because I've built waylandpp with this code to see full stack.

Xwayland version is 22.1.3 (12201003) (old versions have no xdg_shell support).

twaik@twaikPC:~$ WAYLAND_DEBUG=1 ./build-waylandpp-lorie-Desktop-Debug/waylandpp-lorie 
Hello World!
[1997996.676] [email protected]_registry(new id wl_registry@2)
[1997996.738]  -> [email protected](1, "wl_shm", 1)
[1997996.760]  -> [email protected](2, "wl_compositor", 5)
[1997996.775]  -> [email protected](3, "xdg_wm_base", 5)
[1997996.789]  -> [email protected](4, "wl_output", 4)
[1997996.805]  -> [email protected](5, "wl_seat", 8)
[1997996.821] [email protected](new id wl_callback@3)
[1997996.836]  -> [email protected](0)
[1997996.850]  -> [email protected]_id(3)
[1997997.313] [email protected](1, "wl_shm", 1, new id [unknown]@4)
[1997997.349]  -> [email protected](0)
[1997997.361]  -> [email protected](1)
[1997997.369] [email protected](2, "wl_compositor", 4, new id [unknown]@5)
[1997997.410] [email protected](3, "xdg_wm_base", 1, new id [unknown]@6)
[1997997.423] [email protected](4, "wl_output", 2, new id [unknown]@7)
[1997997.453]  -> [email protected](0, 0, 270, 158, 0, "weston-x11", "none", 0)
[1997997.490]  -> [email protected](1)
[1997997.503]  -> [email protected](3, 1024, 600, 60000)
[1997997.516]  -> [email protected]()
[1997997.528] [email protected](new id wl_callback@3)
[1997997.539]  -> [email protected](0)
[1997997.548]  -> [email protected]_id(3)
[1998039.809] [email protected]_pool(new id wl_shm_pool@3, fd 11, 2457600)
[1998039.845] [email protected]_buffer(new id wl_buffer@8, 0, 1024, 600, 4096, 1)
[1998039.852] [email protected]()
[1998039.856]  -> [email protected]_id(3)
[1998039.861] [email protected]_surface(new id wl_surface@9)
[1998039.884] [email protected]_xdg_surface(new id xdg_surface@10, wl_surface@9)
[1998039.891] [email protected]_toplevel(new id xdg_toplevel@11)
[1998039.896] [email protected]()
[1998039.900] [email protected]_region(new id wl_region@12)
[1998039.906] [email protected](0, 0, 1024, 600)
[1998039.913] [email protected]_opaque_region(wl_region@12)
[1998039.918] [email protected]()
[1998055.229] [email protected]_pool(new id wl_shm_pool@13, fd 11, 1024)
[1998055.252] [email protected]_buffer(new id wl_buffer@14, 0, 16, 16, 64, 0)
[1998055.258] [email protected]()
[1998055.267]  -> [email protected]_id(13)
[1998055.271] [email protected]_registry(new id wl_registry@15)
[1998055.275]  -> [email protected](1, "wl_shm", 1)
[1998055.279]  -> [email protected](2, "wl_compositor", 5)
[1998055.283]  -> [email protected](3, "xdg_wm_base", 5)
[1998055.287]  -> [email protected](4, "wl_output", 4)
[1998055.291]  -> [email protected](5, "wl_seat", 8)
[1998055.300] [email protected](new id wl_callback@16)
[1998055.304]  -> [email protected](0)
[1998055.306]  -> [email protected]_id(16)
[1998055.346] [email protected](5, "wl_seat", 5, new id [unknown]@13)
[1998055.358]  -> [email protected](7)
[1998055.362] [email protected]_surface(new id wl_surface@3)
[1998055.368] [email protected](new id wl_callback@16)
[1998055.370]  -> [email protected](0)
[1998055.372]  -> [email protected]_id(16)
[1998056.837] [email protected]_pointer(new id wl_pointer@17)
[1998056.846] [email protected]_cursor(0, nil, 0, 0)
Segmentation fault (core dumped)

if the line starting with pointer.on_set_cursor() is not commented out my app falls with segfault. For some reason data == null is true in resource_t::set_events. It looks like there is a problem when resource_t should be empty...

Qt stacktrace screenshot

image

twaik avatar Jan 19 '23 08:01 twaik