hyprwm / xdg-desktop-portal-hyprland

xdg-desktop-portal backend for Hyprland
BSD 3-Clause "New" or "Revised" License
273 stars 47 forks source link

free(): invalid pointer when trying to screencast with pipewire & wayland #61

Closed MabezDev closed 1 year ago

MabezDev commented 1 year ago

Reproduction

In a terminal, run /usr/libexec/xdg-desktop-portal-hyprland -r -l TRACE, then open obs and add the pipewire screen cast source. As soon as the picker comes up and I choose entire screen the portal crashes with the following output.

2023/05/28 00:11:05 [INFO] - dbus: start method invoked
2023/05/28 00:11:05 [INFO] - dbus: request_handle: /org/freedesktop/portal/desktop/request/1_40/obs5
2023/05/28 00:11:05 [INFO] - dbus: session_handle: /org/freedesktop/portal/desktop/session/1_40/obs2
2023/05/28 00:11:05 [INFO] - dbus: app_id:
2023/05/28 00:11:05 [INFO] - dbus: parent_window:
2023/05/28 00:11:05 [DEBUG] - dbus: start: found matching session /org/freedesktop/portal/desktop/session/1_40/obs2
2023/05/28 00:11:05 [TRACE] - wlroots: callbacks registered
2023/05/28 00:11:05 [TRACE] - wlroots: buffer event handler
2023/05/28 00:11:05 [TRACE] - wlroots: linux_dmabuf event handler
2023/05/28 00:11:05 [TRACE] - wlroots: buffer_done event handler
2023/05/28 00:11:05 [TRACE] - wlroots: finish screencopy
2023/05/28 00:11:05 [TRACE] - wlroots: frame destroyed
2023/05/28 00:11:05 [INFO] - pipewire: stream state changed to "connecting"
2023/05/28 00:11:05 [INFO] - pipewire: node id is -1
2023/05/28 00:11:05 [INFO] - pipewire: stream state changed to "paused"
2023/05/28 00:11:05 [INFO] - pipewire: node id is 50
2023/05/28 00:11:05 [INFO] - xdph: registered restoreToken with token E0978C34-96D0-4717-B391-D70B94B18213
2023/05/28 00:11:05 [DEBUG] - dbus: start: returning node 50
2023/05/28 00:11:06 [TRACE] - event-loop: got pipewire event
2023/05/28 00:11:06 [TRACE] - event-loop: got pipewire event
2023/05/28 00:11:06 [TRACE] - event-loop: got pipewire event
2023/05/28 00:11:06 [TRACE] - event-loop: got pipewire event
2023/05/28 00:11:06 [TRACE] - pipewire: stream parameters changed
2023/05/28 00:11:06 [DEBUG] - pipewire: Format negotiated:
2023/05/28 00:11:06 [DEBUG] - pipewire: buffer_type: 0 (4)
2023/05/28 00:11:06 [DEBUG] - pipewire: format: 7free
2023/05/28 00:11:06 [DEBUG] - pipewire: modifier: 0
2023/05/28 00:11:06 [DEBUG] - pipewire: size: (2560, 1600)
2023/05/28 00:11:06 [DEBUG] - pipewire: max_framerate: (60 / 1)
free(): invalid pointer
[1]    3754 IOT instruction  /usr/libexec/xdg-desktop-portal-hyprland -r -l TRACE

I am currently running this on an arm64 machine (Macbook M1) with the following Hyprland/xdg versions:

I'm guess arm64 might have something to do with this, as I haven't seen any reports of this happening on AMD64 (in my searches).

Happy to aid in debugging this in any way possible, just not sure where to start right now.

MabezDev commented 1 year ago

Not sure if this is related, or just another issue, but streaming a window yields a different issue before it even negoiates with pipewire:

2023/05/28 01:07:14 [TRACE] - event-loop: got dbus event
2023/05/28 01:07:14 [TRACE] - event-loop: got dbus event
2023/05/28 01:07:14 [TRACE] - event-loop: got dbus event
2023/05/28 01:07:14 [INFO] - dbus: create session method invoked
2023/05/28 01:07:14 [INFO] - dbus: request_handle: /org/freedesktop/portal/desktop/request/1_47/webrtc_1583700603
2023/05/28 01:07:14 [INFO] - dbus: session_handle: /org/freedesktop/portal/desktop/session/1_47/webrtc_session569564115
2023/05/28 01:07:14 [INFO] - dbus: app_id:
2023/05/28 01:07:14 [TRACE] - event-loop: got dbus event
2023/05/28 01:07:14 [TRACE] - event-loop: got dbus event
2023/05/28 01:07:14 [INFO] - dbus: select sources method invoked
2023/05/28 01:07:14 [INFO] - dbus: request_handle: /org/freedesktop/portal/desktop/request/1_47/webrtc2117633139
2023/05/28 01:07:14 [INFO] - dbus: session_handle: /org/freedesktop/portal/desktop/session/1_47/webrtc_session569564115
2023/05/28 01:07:14 [INFO] - dbus: app_id:
2023/05/28 01:07:14 [INFO] - dbus: option types:2
2023/05/28 01:07:14 [INFO] - dbus: option multiple: 0
2023/05/28 01:07:14 [INFO] - dbus: persist 1
2023/05/28 01:07:14 [DEBUG] - dbus: select sources: found matching session /org/freedesktop/portal/desktop/session/1_47/webrtc_session569564115
2023/05/28 01:07:14 [INFO] - wlroots: capturable output: Unknown model: Unknown: id: 48 name: eDP-1
2023/05/28 01:07:14 [DEBUG] - Screencast: Picker: Running command "WAYLAND_DISPLAY=wayland-1 QT_QPA_PLATFORM="wayland" XCURSOR_SIZE=24 HYPRLAND_INSTANCE_SIGNATURE=f27873a6f06dc2f87600edb890f3c38298bfb55f_1685232199 XDPH_WINDOW_SHARING_LIST="3333740896[HC>]Alacritty[HT>]Alacritty[HE>]3333740496[HC>]Alacritty[HT>]Alacritty[HE>]3333740144[HC>]chromium-browser-chromium[HT>]gUM Test Page - Chromium[HE>]" hyprland-share-picker"
MabezDev commented 1 year ago

Hmm, looking at the arch package, it is shipped with a precompiled libwlroots... I guess using system wlroots is not possible. Where are the sources for the wlroots Hyprland uses? I think I will have to compile these for arm64.

MabezDev commented 1 year ago

Building git wlroots (was previously 0.16.2) didn't seem to change anything, still crashes with fullscreen and prints the error above when trying to share a window :/

EDIT: and I've just realised the hyperland source includes the wlroots source too! So this step was completely pointless. Still, that error sure is odd :thinking:.

vaxerski commented 1 year ago

a coredump with a stacktrace would be useful

MabezDev commented 1 year ago
gdb /usr/libexec/xdg-desktop-portal-hyprland -c core-xdg-desktop-por.31330.mAsahi.1685277614
GNU gdb (Gentoo 13.1.90_p20230325 vanilla) 13.1.90.20230325-git
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "aarch64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://bugs.gentoo.org/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/libexec/xdg-desktop-portal-hyprland...

warning: Can't open file /memfd:pipewire-memfd:flags=0x0000000f,type=2,size=2312 (deleted) during file-backed mapping note processing

warning: core file may not match specified executable file.
[New LWP 31330]
[New LWP 31331]
[New LWP 31333]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `/usr/libexec/xdg-desktop-portal-hyprland -r -l TRACE'.
Program terminated with signal SIGABRT, Aborted.
#0  0x0000ffff86cb05d0 in ?? () from /lib64/libc.so.6
[Current thread is 1 (Thread 0xffff870ec1a0 (LWP 31330))]
(gdb) bt
#0  0x0000ffff86cb05d0 in ?? () from /lib64/libc.so.6
#1  0x0000ffff86c6a3ac in raise () from /lib64/libc.so.6
#2  0x0000ffff86c570fc in abort () from /lib64/libc.so.6
#3  0x0000ffff86ca46ac in ?? () from /lib64/libc.so.6
#4  0x0000ffff86cbaa1c in ?? () from /lib64/libc.so.6
#5  0x0000ffff86cbc768 in ?? () from /lib64/libc.so.6
#6  0x0000ffff86cbedf4 in free () from /lib64/libc.so.6
#7  0x0000aaab965145e0 in spa_pod_dynamic_builder_clean (builder=0xffffe5fbae88)
    at /usr/include/spa-0.2/spa/pod/dynamic.h:54
#8  0x0000aaab965159a8 in pwr_handle_stream_param_changed (data=0xaaabcfa16530, id=4, param=0xaaabcf98eab8)
    at ../xdg-desktop-portal-hyprland-0.3.1/src/screencast/pipewire_screencast.c:334
#9  0x0000ffff86f37af0 in ?? () from /usr/lib64/libpipewire-0.3.so.0
#10 0x0000ffff86f2b988 in pw_impl_port_set_param () from /usr/lib64/libpipewire-0.3.so.0
#11 0x0000ffff86904ed8 in ?? () from /usr/lib64/pipewire-0.3/libpipewire-module-client-node.so
#12 0x0000ffff869102ec in ?? () from /usr/lib64/pipewire-0.3/libpipewire-module-client-node.so
#13 0x0000ffff8697674c in ?? () from /usr/lib64/pipewire-0.3/libpipewire-module-protocol-native.so
#14 0x0000ffff86976d3c in ?? () from /usr/lib64/pipewire-0.3/libpipewire-module-protocol-native.so
#15 0x0000ffff86a78f60 in ?? () from /usr/lib64/spa-0.2/support/libspa-support.so
#16 0x0000aaab96506a7c in main (argc=4, argv=0xffffe5fbc748)
    at ../xdg-desktop-portal-hyprland-0.3.1/src/core/main.c:243
(gdb)

Here is the core dump: coredump.zip

ming900518 commented 1 year ago

I seem to have encountered the same issue when trying to screencast in Firefox.

image

I managed to make it work by removing line 334 in src/screencast/pipewire_screencast.c

I don't know if this fix has any side effects, though.

vaxerski commented 1 year ago

closing due to the v1.0 rewrite