russelltg / wl-screenrec

High performance wlroots screen recording, featuring hardware encoding
Apache License 2.0
266 stars 9 forks source link

"invalid buffer dimensions" protocol error with fractional scaling #10

Closed git-bruh closed 1 year ago

git-bruh commented 1 year ago

Hey, when the scale in sway is set to fractional values like 1.25 or 1.5, wlroots returns a protocol error, causing this exception

Protocol error 1 on object zwlr_screencopy_frame_v1@11: invalid buffer dimensions
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Backend(Protocol(ProtocolError { code: 1, object_id: 11, object_interface: "zwlr_screencopy_frame_v1", message: "invalid buffer dimensions" }))', src/main.rs:1004:45

This is because the logical_size returned varies depending upon the scale, at a scale of 1, it returns 1920x1080, 1536x864 at 1.25, and 1280x720 at 1.5

[1684867534.728096] <- wl_output@7.geometry, (0, 0, 340, 190, 0, Some("AU Optronics"), Some("0x2992"), 0)
[1684867534.728138] <- wl_output@7.mode, (1, 1920, 1080, 144149)
[1684867534.728157] <- wl_output@7.scale, (2)
[1684867534.728169] <- wl_output@7.name, (Some("eDP-1"))
[1684867534.728190] <- wl_output@7.description, (Some("AU Optronics 0x2992 (eDP-1)"))
[1684867534.728220] <- wl_output@7.done, ()
[1684867534.728230] <- zxdg_output_v1@8.name, (Some("eDP-1"))
[1684867534.728253] <- zxdg_output_v1@8.description, (Some("AU Optronics 0x2992 (eDP-1)"))
[1684867534.728288] <- zxdg_output_v1@8.logical_position, (0, 0)
[1684867534.728304] <- zxdg_output_v1@8.logical_size, (1536, 864)
[1684867534.728318] <- wl_output@7.done, ()
Using output eDP-1
[libx264 @ 0x55cab717ce40] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x55cab717ce40] profile Constrained Baseline, level 5.1, 4:2:0, 8-bit
[1684867534.789019] -> zwp_linux_dmabuf_v1@4.create_params (zwp_linux_buffer_params_v1@9)
[1684867534.789120] -> zwp_linux_buffer_params_v1@9.add (11, 0, 0, 6144, 0, 0)
[1684867534.789150] -> zwp_linux_buffer_params_v1@9.create_immed (wl_buffer@10, 1536, 864, 875713112, 0)
[1684867534.789209] -> zwlr_screencopy_manager_v1@3.capture_output (zwlr_screencopy_frame_v1@11, 1, wl_output@7)
[1684867534.789237] -> zwlr_screencopy_frame_v1@11.copy_with_damage (wl_buffer@10)
[1684867534.791877] <- zwlr_screencopy_frame_v1@11.buffer, (875709016, 1920, 1080, 7680)
[1684867534.791899] <- zwlr_screencopy_frame_v1@11.linux_dmabuf, (875713112, 1920, 1080)
[1684867534.791912] <- zwlr_screencopy_frame_v1@11.buffer_done, ()
[1684867534.791924] <- wl_display@1.error, (11, 1, Some("invalid buffer dimensions"))
Protocol error 1 on object zwlr_screencopy_frame_v1@11: invalid buffer dimensions
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Backend(Protocol(ProtocolError { code: 1, object_id: 11, object_interface: "zwlr_screencopy_frame_v1", message: "invalid buffer dimensions" }))', src/main.rs:1004:45

Code in wlroots

https://gitlab.freedesktop.org/wlroots/wlroots/-/blob/master/types/wlr_screencopy_v1.c#L357

Thanks! Didn't get enough time to debug this further

TreyBastian commented 1 year ago

I'm facing the same error in Hyprland with scaling set to 2

russelltg commented 1 year ago

Mostly done with a fix, should get it pushed later today :)

russelltg commented 1 year ago

Okay, this should work nicely now, at least with scales that are multiples of .25. For some reason it's not working with scales like 1.1, 1.2, and I suspect it's not my fault but I'm not sure.

russelltg commented 1 year ago

Please reopen if it doesn't work

Stetsed commented 1 year ago

@russelltg Running into the issue with a scaling of 1.5 running the AUR git package

russelltg commented 1 year ago

Can you give the exact version (pacman -Qi wl-screenrec-git) and also which compositor you use? It works for me with r72.7b367d3-1 and hyprland.

Edit: works fine on sway too

Stetsed commented 1 year ago

@russelltg Looks like i was running an older version, my mistake.