Skip to content

Stream chooser fixups - #492

Open
soreau wants to merge 3 commits into
masterfrom
stream-chooser-fixups
Open

soreau wants to merge 3 commits into
masterfrom
stream-chooser-fixups

Conversation

@soreau

@soreau soreau commented Jun 21, 2026

Copy link
Copy Markdown
Member

No description provided.

@soreau
soreau force-pushed the stream-chooser-fixups branch from 7b94b32 to f29ef2e Compare June 22, 2026 04:38
@trigg

trigg commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Updated to latest wayfire & copy-capture.

Running up 10 maximized terminals on wf-stream-chooser master, no problem.

With this PR it invokes OOM killer which somehow always chooses Wayfire.

@soreau

soreau commented Jul 12, 2026

Copy link
Copy Markdown
Member Author

Can you try this patch to see if it makes a difference?

diff --git a/src/stream-chooser/outputwidget.cpp b/src/stream-chooser/outputwidget.cpp
index 306809e..a34f926 100644
--- a/src/stream-chooser/outputwidget.cpp
+++ b/src/stream-chooser/outputwidget.cpp
@@ -23,25 +23,17 @@ static void frame_handle_presentation_time(void*,
 {}
 
 static void frame_handle_ready(void *data,
-    struct ext_image_copy_capture_frame_v1 *frame)
+    struct ext_image_copy_capture_frame_v1*)
 {
     WayfireChooserOutput *output = (WayfireChooserOutput*)data;
 
     output->buffer_ready();
-
-    ext_image_copy_capture_frame_v1_destroy(frame);
-    output->frame = nullptr;
 }
 
-static void frame_handle_failed(void *data,
-    struct ext_image_copy_capture_frame_v1 *frame,
+static void frame_handle_failed(void*,
+    struct ext_image_copy_capture_frame_v1*,
     uint32_t reason)
-{
-    WayfireChooserOutput *output = (WayfireChooserOutput*)data;
-
-    ext_image_copy_capture_frame_v1_destroy(frame);
-    output->frame = nullptr;
-}
+{}
 
 static const struct ext_image_copy_capture_frame_v1_listener frame_listener = {
     .transform = frame_handle_transform,
diff --git a/src/stream-chooser/toplevelwidget.cpp b/src/stream-chooser/toplevelwidget.cpp
index 380744e..deec9ad 100644
--- a/src/stream-chooser/toplevelwidget.cpp
+++ b/src/stream-chooser/toplevelwidget.cpp
@@ -123,25 +123,17 @@ static void frame_handle_presentation_time(void*,
 {}
 
 static void frame_handle_ready(void *data,
-    struct ext_image_copy_capture_frame_v1 *frame)
+    struct ext_image_copy_capture_frame_v1*)
 {
     WayfireChooserTopLevel *toplevel = (WayfireChooserTopLevel*)data;
 
     toplevel->buffer_ready();
-
-    ext_image_copy_capture_frame_v1_destroy(frame);
-    toplevel->frame = nullptr;
 }
 
-static void frame_handle_failed(void *data,
-    struct ext_image_copy_capture_frame_v1 *frame,
+static void frame_handle_failed(void*,
+    struct ext_image_copy_capture_frame_v1*,
     uint32_t reason)
-{
-    WayfireChooserTopLevel *toplevel = (WayfireChooserTopLevel*)data;
-
-    ext_image_copy_capture_frame_v1_destroy(frame);
-    toplevel->frame = nullptr;
-}
+{}
 
 static const struct ext_image_copy_capture_frame_v1_listener frame_listener = {
     .transform = frame_handle_transform,

@trigg

trigg commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

With that patch I get thrown back to login when I have too many terminals open

wf-stream-choos[24679]: segfault at 40 ip 00007f5911bee1c4 sp 00007fffd6a6d3f8 error 4 in libwayland-client.so.0.25.0[51c4,7f5911bec000+7000] likely on CPU 15 (core 7, socket 0)

No crash but clearly struggling without this PR.

Will attempt to catch a log this time

@trigg

trigg commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator
Thread 1 "wayfire" received signal SIGABRT, Aborted.
__pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
44            return INTERNAL_SYSCALL_ERROR_P (ret) ? INTERNAL_SYSCALL_ERRNO (ret) : 0;
#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x00007ffff729a163 in __pthread_kill_internal (threadid=<optimized out>, signo=6) at pthread_kill.c:89
#2  0x00007ffff723e5d0 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x00007ffff7225685 in __GI_abort () at abort.c:77
#4  0x00007ffff7226704 in __libc_message_impl (vma_name=vma_name@entry=0x7ffff73b6908 "glibc: assert", fmt=<optimized out>) at ../sysdeps/posix/libc_fatal.c:138
#5  0x00007ffff72361f2 in __libc_message_wrapper (vmaname=0x7ffff73b6908 "glibc: assert", fmt=<optimized out>) at ../include/stdio.h:203
#6  __assert_fail (assertion=assertion@entry=0x7ffff7e85578 "wl_list_empty(&backend->events.new_input.listener_list)", file=file@entry=0x7ffff7e79e92 "backend/backend.c", line=line@entry=51, function=function@entry=0x7ffff7eb1ca0 <__PRETTY_FUNCTION__.1.lto_priv.19> "wlr_backend_finish") at assert.c:37
#7  0x00007ffff7dc4d3d in wlr_backend_finish (backend=0x555555774fa0) at ../wlroots0.20/backend/backend.c:51
#8  0x00007ffff7e0b3a4 in multi_backend_destroy (wlr_backend=0x555555774fa0) at ../wlroots0.20/backend/multi/backend.c:52
#9  0x00007ffff7efb590 in wl_signal_emit_mutable (signal=signal@entry=0x55555578d320, data=data@entry=0x55555578d310) at ../wayland-1.25.0/src/wayland-server.c:2396
#10 0x00007ffff7deb5a0 in wlr_backend_finish (backend=backend@entry=0x55555578d310) at ../wlroots0.20/backend/backend.c:48
#11 0x00007ffff7df4672 in backend_destroy (backend=0x55555578d310) at ../wlroots0.20/backend/drm/backend.c:47
#12 0x00007ffff7dfba79 in handle_drm_event (fd=<optimized out>, mask=<optimized out>, data=0x55555578d310) at ../wlroots0.20/backend/drm/drm.c:2099
#13 handle_drm_event (fd=<optimized out>, mask=<optimized out>, data=0x55555578d310) at ../wlroots0.20/backend/drm/drm.c:2089
#14 0x00007ffff7efd3d2 in wl_event_loop_dispatch (loop=0x5555557751b0, timeout=<optimized out>, timeout@entry=-1) at ../wayland-1.25.0/src/event-loop.c:1059
#15 0x00007ffff7eff567 in wl_display_run (display=0x5555557750c0) at ../wayland-1.25.0/src/wayland-server.c:1593
#16 0x00005555555e3bce in main ()

So, specifically with stream-chooser from this PR.

It appears to happen sometimes when a window is added (Using Meta+T to open a terminal in my case)

Although I'm not seeing the 'how' here

@soreau

soreau commented Jul 26, 2026

Copy link
Copy Markdown
Member Author

This seems very similar to the issue here.

@trigg trigg added enhancement New feature or request streamer labels Aug 1, 2026
@soreau

soreau commented Sep 6, 2026

Copy link
Copy Markdown
Member Author

Can you build with asan by passing -Db_sanitize=address,undefined to meson and reproduce the problem in efforts to get a better trace? Maybe do the same with wf-shell and pipe the output of wf-stream-chooser to file, in case it happens to dump anything interesting too.

@soreau

soreau commented Oct 10, 2026

Copy link
Copy Markdown
Member Author

Another thing that came to mind is system resource limits. You can check limits with ulimit -a and set a new limit. To increase file descriptor limits for example, use ulimit -n 65536.

@soreau
soreau force-pushed the stream-chooser-fixups branch from f29ef2e to 66ee35b Compare November 2, 2026 10:27
@trigg

trigg commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

$ wayfire --version
0.12.0-e268d4e5 (Nov 2 2026) branch master wlroots-0.20.2

$ ./build/src/stream-chooser/wf-stream-chooser --version
wf-shell version 0.11.1-66ee35b (2026-06-21) branch stream-chooser-fixups gtk 4.22.0

(wf-copy-capture) &git show --oneline -s
ec0f716 (HEAD -> master, origin/master, origin/HEAD) Drop damage tracking

I tried with ASAN but it doesn't product a backtrace, so GDB it is again

EE 2026-11-02 17:14:42.174 - [backend/drm/drm.c:2098] drmHandleEvent failed
II 2026-11-02 17:14:42.174 - [src/core/output-layout.cpp:1630] remove output: eDP-1
II 2026-11-02 17:14:42.174 - [src/core/output-layout.cpp:1511] new output: NOOP-1
II 2026-11-02 17:14:42.175 - [src/core/output-layout.cpp:926] Couldn't find matching mode 1280x720@0 for output NOOP-1. Trying to use custom mode(might not work)
EE 2026-11-02 17:14:42.202 - [src/core/output-layout.cpp:817] disabling output: eDP-1
II 2026-11-02 17:14:42.208 - [src/core/output-layout.cpp:379] transfer views from eDP-1 -> NOOP-1
II 2026-11-02 17:14:42.300 - [backend/drm/drm.c:984] connector eDP-1: Turning off

Thread 1 "wayfire" received signal SIGABRT, Aborted.
Downloading source file /usr/src/debug/glibc/glibc/nptl/pthread_kill.c...
__pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
44	      return INTERNAL_SYSCALL_ERROR_P (ret) ? INTERNAL_SYSCALL_ERRNO (ret) : 0;
#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x00007ffff5c9a1e3 in __pthread_kill_internal (threadid=<optimized out>, signo=6) at pthread_kill.c:89
#2  0x00007ffff5c3e5d0 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x00007ffff5c25685 in __GI_abort () at abort.c:77
#4  0x00007ffff5c26704 in __libc_message_impl (vma_name=vma_name@entry=0x7ffff5db9908 "glibc: assert", fmt=<optimized out>) at ../sysdeps/posix/libc_fatal.c:138
#5  0x00007ffff5c361f2 in __libc_message_wrapper (vmaname=0x7ffff5db9908 "glibc: assert", fmt=<optimized out>) at ../include/stdio.h:203
#6  __assert_fail (assertion=assertion@entry=0x7ffff7005578 "wl_list_empty(&backend->events.new_input.listener_list)", file=file@entry=0x7ffff6ff9e92 "backend/backend.c", line=line@entry=51, function=function@entry=0x7ffff7031ca0 <__PRETTY_FUNCTION__.1.lto_priv.19> "wlr_backend_finish") at assert.c:37
#7  0x00007ffff6f44d3d in wlr_backend_finish (backend=0x7ccff25e0450) at ../wlroots0.20/backend/backend.c:51
#8  0x00007ffff6f8b3a4 in multi_backend_destroy (wlr_backend=0x7ccff25e0450) at ../wlroots0.20/backend/multi/backend.c:52
#9  0x00007ffff7f77740 in wl_signal_emit_mutable (signal=signal@entry=0x7d3ff25e9850, data=data@entry=0x7d3ff25e9840) at ../wayland-1.26.0/src/wayland-server.c:2576
#10 0x00007ffff6f6b5a0 in wlr_backend_finish (backend=backend@entry=0x7d3ff25e9840) at ../wlroots0.20/backend/backend.c:48
#11 0x00007ffff6f74672 in backend_destroy (backend=0x7d3ff25e9840) at ../wlroots0.20/backend/drm/backend.c:47
#12 0x00007ffff6f7ba79 in handle_drm_event (fd=<optimized out>, mask=<optimized out>, data=0x7d3ff25e9840) at ../wlroots0.20/backend/drm/drm.c:2099
#13 handle_drm_event (fd=<optimized out>, mask=<optimized out>, data=0x7d3ff25e9840) at ../wlroots0.20/backend/drm/drm.c:2089
#14 0x00007ffff7f79992 in wl_event_loop_dispatch (loop=0x7cdff25e03c0, timeout=<optimized out>) at ../wayland-1.26.0/src/event-loop.c:1059
#15 0x00007bffcf25b9e7 in source_request_frame (source=0x7d7ff26bcea8, schedule_frame=false) at ../copy-capture.cpp:432
#16 0x00007ffff6b4cdb6 in ffi_call_unix64 () at ../src/x86/unix64.S:105
#17 0x00007ffff6b48a6d in ffi_call_int (cif=<optimized out>, fn=<optimized out>, rvalue=<optimized out>, avalue=<optimized out>, closure=closure@entry=0x0) at ../src/x86/ffi64.c:772
#18 0x00007ffff6b4be32 in ffi_call (cif=cif@entry=0x7fffffffc9a0, fn=<optimized out>, rvalue=rvalue@entry=0x0, avalue=<optimized out>, avalue@entry=0x7fffffffca70) at ../src/x86/ffi64.c:1165
#19 0x00007ffff7f75672 in wl_closure_invoke (closure=closure@entry=0x7d0ff2ecf200, target=<optimized out>, target@entry=0x7cbff2abf2c0, opcode=opcode@entry=3, data=<optimized out>, data@entry=0x7d0ff2b9d500, flags=2) at ../wayland-1.26.0/src/connection.c:1243
#20 0x00007ffff7f7b618 in wl_client_connection_data (fd=<optimized out>, mask=<optimized out>, data=<optimized out>) at ../wayland-1.26.0/src/wayland-server.c:498
#21 0x00007ffff7f79992 in wl_event_loop_dispatch (loop=0x7cdff25e03c0, timeout=<optimized out>, timeout@entry=-1) at ../wayland-1.26.0/src/event-loop.c:1059
#22 0x00007ffff7f7bb87 in wl_display_run (display=0x7d0ff25e0cc0) at ../wayland-1.26.0/src/wayland-server.c:1741
#23 0x00005555556a9c66 in main ()

@soreau

soreau commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

Can you clarify steps to reproduce? What terminal applications are you using, etc.

@trigg

trigg commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

xfce4-terminal

Just launch a handful of them and then start the stream-chooser.

It can also be triggered by starting stream-chooser alone and launching more terminals until it hits.

I'll submit this now and then try get a concrete number of terminals to cause a crash in my case

@trigg

trigg commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

10 on first count

@soreau

soreau commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

Ok I can reproduce it with xfce4-terminal, though it seems I have to run like 15+ to trigger it. Thanks, I will investigate further.

@trigg

trigg commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

2 🤷

@soreau

soreau commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

@trigg Can you try this wlroots patch? It seems to fix the problem here.

diff --git a/backend/drm/drm.c b/backend/drm/drm.c
index bd29872f..5717ffa4 100644
--- a/backend/drm/drm.c
+++ b/backend/drm/drm.c
@@ -2094,7 +2094,7 @@ int handle_drm_event(int fd, uint32_t mask, void *data) {
                .page_flip_handler2 = handle_page_flip,
        };
 
-       if (drmHandleEvent(fd, &event) != 0) {
+       if (drmHandleEvent(fd, &event) != 0 && errno != EAGAIN) {
                wlr_log(WLR_ERROR, "drmHandleEvent failed");
                wlr_backend_destroy(&drm->backend);
        }

@trigg

trigg commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator
$ ./build/src/stream-chooser/wf-stream-chooser

(wf-stream-chooser:58007): Gdk-WARNING **: 09:52:48.638: vkGetPhysicalDeviceSurfacePresentModesKHR(): A surface is no longer available. (VK_ERROR_SURFACE_LOST_KHR) (-1000000000)
Gdk-Message: 09:52:48.690: Error 22 (Invalid argument) dispatching to Wayland display.

And with WAYLAND_DEBUG=1 it doesn't crash.

Same method. pile of terminals and launch chooser. This time it's the chooser that crashes so much less drastic

@soreau

soreau commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

Does it help you there if you try GSK_RENDERER=gl when starting stream-chooser?

@trigg

trigg commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

with GL renderer it hung my input and output for several minutes until I pressed suspend. After resume I got

frame_request invalid size
frame_request invalid size
frame_request invalid size
Gdk-Message: 16:41:35.436: Error flushing display: Resource temporarily unavailable

Which is probably quite unhelpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request streamer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants