Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crashes on Sway - not divisible by scale 2 #2445

Open
grant0417 opened this issue Aug 22, 2022 · 21 comments
Open

Crashes on Sway - not divisible by scale 2 #2445

grant0417 opened this issue Aug 22, 2022 · 21 comments
Labels
bug Something isn't working Wayland

Comments

@grant0417
Copy link
Contributor

grant0417 commented Aug 22, 2022

What Operating System(s) are you seeing this problem on?

Linux Wayland

Which Wayland compositor or X11 Window manager(s) are you using?

sway version 1.8-dev-6e023257

WezTerm version

wezterm 20220821-181413-35ed9ac1

Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?

Yes, and I updated the version box above to show the version of the nightly that I tried

Describe the bug

Wezterm crashes when multiple windows are opened in a vertical layout in Sway

Seems related to #1144

To Reproduce

No response

Configuration

Happens with and without config

Expected Behavior

No response

Logs

19:45:06.046  WARN   wezterm_gui::termwindow::resize        > cannot resize window to match Some(RowsAndCols { rows: 13, cols: 82 }) because window_state is MAXIMIZED
19:45:06.060  ERROR  wezterm_gui                            > running message loop: error during event_q.dispatch protocol_error=Some(ProtocolError { code: 2, object_id: 47, object_interface: "wl_surface", message: "" }): Protocol error (os error 71); terminating

Anything else?

No response

@grant0417 grant0417 added the bug Something isn't working label Aug 22, 2022
@wez
Copy link
Owner

wez commented Aug 22, 2022

Please launch wezterm with WAYLAND_DEBUG=1 set in the environment and share the output.

@wez wez added Wayland waiting-on-op Waiting for more information from the original poster labels Aug 22, 2022
@grant0417
Copy link
Contributor Author

Here are the full logs, but here are the last few lines, it seems like there is an issue when the buffer size is not dividable by 2.

[1017736.510] wl_display@1.delete_id(38)
[1017736.514] wl_display@1.delete_id(34)
[1017736.516] wl_display@1.delete_id(46)
[1017736.525] wl_display@1.delete_id(50)
[1017736.527] wl_display@1.error(wl_surface@37, 2, "Buffer size (748x485) is not divisible by scale (2)")
wl_surface@37: error 2: Buffer size (748x485) is not divisible by scale (2)
08:38:18.685  ERROR  wezterm_gui                            > running message loop: error during event_q.dispatch protocol_error=Some(ProtocolError { code: 2, object_id: 37, object_interface: "wl_surface", message: "" }): Protocol error (os error 71); terminating

@github-actions github-actions bot removed the waiting-on-op Waiting for more information from the original poster label Aug 22, 2022
@grant0417
Copy link
Contributor Author

Also unrelated, but would you be open to a pr to suppress the OSC warning with OSC 697 (Fig's proprietary OSCs)

@wez
Copy link
Owner

wez commented Aug 22, 2022

Also unrelated, but would you be open to a pr to suppress the OSC warning with OSC 697 (Fig's proprietary OSCs)

Yeah, however: some of them (most of them?) map to iTerm2 OSCs and could actually be handled the same way.

@wez
Copy link
Owner

wez commented Aug 22, 2022

@q234rty
Copy link

q234rty commented Jan 27, 2023

sway 1.8 is released and this is still reproducible.
Edit: hmmm apparently I can't reproduce it anymore while I clearly remember hitting the exact same error in env WAYLAND_DEBUG=1 wezterm a few days ago with the same version of wezterm...

@hahuang65
Copy link
Contributor

I'm still getting this as well, after installing wezterm-git on Arch:

[2122409.356] wl_display@1.error(wl_surface@106, 2, "Buffer size (1251x1360) is not divisible by scale (2)")
wl_surface@106: error 2: Buffer size (1251x1360) is not divisible by scale (2)
20:17:32.915  ERROR  wezterm_gui                     > running message loop: error during event_q.dispatch protocol_error=Some(ProtocolError { code: 2, object_id: 106, object_interface: "wl_surface", message: "" }): Protocol error (os error 71); terminating

@foosinn
Copy link

foosinn commented Jan 31, 2023

Same here

[3606417.193] wl_display@1.delete_id(53)
[3606417.196] wl_display@1.delete_id(57)
[3606417.198] wl_display@1.error(wl_surface@35, 2, "Buffer size (890x1095) is not divisible by scale (2)")
wl_surface@35: error 2: Buffer size (890x1095) is not divisible by scale (2)
00:39:15.591  ERROR  wezterm_gui                     > running message loop: error during event_q.dispatch protocol_error=Some(ProtocolError { code: 2, object_id: 35, obj

@gfauredev
Copy link

Starting wezterm with the line wezterm start --always-new-process seems to fix this issue, although I don’t really know why.

@glyh
Copy link

glyh commented Feb 4, 2023

Same here, wezterm start --always-new-process doesn't fix it for me.

sway version : sway version 1.9-dev-53c9a4a6 (Jan 17 2023, branch 'master')

Any ideas on how to start this in xwayland though?

[3432981.177]  -> wl_display@1.get_registry(new id wl_registry@2)
[3432981.210]  -> wl_display@1.sync(new id wl_callback@3)
[3432981.508] wl_display@1.delete_id(3)
[3432981.533] wl_registry@2.global(1, "wl_shm", 1)
[3432981.561]  -> wl_registry@2.bind(1, "wl_shm", 1, new id [unknown]@4)
[3432981.571] wl_registry@2.global(2, "wl_drm", 2)
[3432981.576] wl_registry@2.global(3, "zwp_linux_dmabuf_v1", 4)
[3432981.584] wl_registry@2.global(4, "wl_compositor", 5)
[3432981.595]  -> wl_registry@2.bind(4, "wl_compositor", 5, new id [unknown]@5)
[3432981.601] wl_registry@2.global(5, "wl_subcompositor", 1)
[3432981.609]  -> wl_registry@2.bind(5, "wl_subcompositor", 1, new id [unknown]@6)
[3432981.615] wl_registry@2.global(6, "wl_data_device_manager", 3)
[3432981.622]  -> wl_registry@2.bind(6, "wl_data_device_manager", 3, new id [unknown]@7)
[3432981.628] wl_registry@2.global(7, "zwlr_gamma_control_manager_v1", 1)
[3432981.634] wl_registry@2.global(8, "zxdg_output_manager_v1", 3)
[3432981.640] wl_registry@2.global(9, "org_kde_kwin_idle", 1)
[3432981.645] wl_registry@2.global(10, "ext_idle_notifier_v1", 1)
[3432981.651] wl_registry@2.global(11, "zwp_idle_inhibit_manager_v1", 1)
[3432981.656] wl_registry@2.global(12, "zwlr_layer_shell_v1", 3)
[3432981.661] wl_registry@2.global(13, "xdg_wm_base", 2)
[3432981.666] wl_registry@2.global(14, "zwp_tablet_manager_v2", 1)
[3432981.672] wl_registry@2.global(15, "org_kde_kwin_server_decoration_manager", 1)
[3432981.677] wl_registry@2.global(16, "zxdg_decoration_manager_v1", 1)
[3432981.687]  -> wl_registry@2.bind(16, "zxdg_decoration_manager_v1", 1, new id [unknown]@8)
[3432981.694] wl_registry@2.global(17, "zwp_relative_pointer_manager_v1", 1)
[3432981.698] wl_registry@2.global(18, "zwp_pointer_constraints_v1", 1)
[3432981.703] wl_registry@2.global(19, "wp_presentation", 1)
[3432981.708] wl_registry@2.global(20, "zwlr_output_manager_v1", 4)
[3432981.713] wl_registry@2.global(21, "zwlr_output_power_manager_v1", 1)
[3432981.719] wl_registry@2.global(22, "zwp_input_method_manager_v2", 1)
[3432981.724] wl_registry@2.global(23, "zwp_text_input_manager_v3", 1)
[3432981.729]  -> wl_registry@2.bind(23, "zwp_text_input_manager_v3", 1, new id [unknown]@9)
[3432981.739] wl_registry@2.global(24, "zwlr_foreign_toplevel_manager_v1", 3)
[3432981.745] wl_registry@2.global(25, "ext_session_lock_manager_v1", 1)
[3432981.749] wl_registry@2.global(26, "wp_drm_lease_device_v1", 1)
[3432981.754] wl_registry@2.global(27, "zwlr_export_dmabuf_manager_v1", 1)
[3432981.759] wl_registry@2.global(28, "zwlr_screencopy_manager_v1", 3)
[3432981.764] wl_registry@2.global(29, "zwlr_data_control_manager_v1", 2)
[3432981.769] wl_registry@2.global(30, "wp_viewporter", 1)
[3432981.773] wl_registry@2.global(31, "wp_single_pixel_buffer_manager_v1", 1)
[3432981.778] wl_registry@2.global(32, "wp_content_type_manager_v1", 1)
[3432981.783] wl_registry@2.global(33, "zxdg_exporter_v1", 1)
[3432981.788] wl_registry@2.global(34, "zxdg_importer_v1", 1)
[3432981.793] wl_registry@2.global(35, "zxdg_exporter_v2", 1)
[3432981.800] wl_registry@2.global(36, "zxdg_importer_v2", 1)
[3432981.803] wl_registry@2.global(37, "xdg_activation_v1", 1)
[3432981.810] wl_registry@2.global(38, "zwp_virtual_keyboard_manager_v1", 1)
[3432981.815] wl_registry@2.global(39, "zwlr_virtual_pointer_manager_v1", 2)
[3432981.820] wl_registry@2.global(40, "zwlr_input_inhibit_manager_v1", 1)
[3432981.824] wl_registry@2.global(41, "zwp_keyboard_shortcuts_inhibit_manager_v1", 1)
[3432981.829] wl_registry@2.global(42, "wl_seat", 8)
[3432981.835]  -> wl_registry@2.bind(42, "wl_seat", 6, new id [unknown]@10)
[3432981.843] wl_registry@2.global(43, "zwp_pointer_gestures_v1", 3)
[3432981.848] wl_registry@2.global(44, "xwayland_shell_v1", 1)
[3432981.853] wl_registry@2.global(45, "zwp_primary_selection_device_manager_v1", 1)
[3432981.858] wl_registry@2.global(46, "wl_output", 4)
[3432981.866]  -> wl_registry@2.bind(46, "wl_output", 3, new id [unknown]@11)
[3432981.873] wl_callback@3.done(53878)
[3432981.881]  -> wl_display@1.sync(new id wl_callback@3)
[3432982.026] wl_display@1.delete_id(3)
[3432982.038] wl_shm@4.format(0)
[3432982.046] wl_shm@4.format(1)
[3432982.050] wl_shm@4.format(875709016)
[3432982.055] wl_shm@4.format(875708993)
[3432982.059] wl_shm@4.format(875710274)
[3432982.065] wl_shm@4.format(842094674)
[3432982.069] wl_shm@4.format(842088786)
[3432982.073] wl_shm@4.format(892426322)
[3432982.079] wl_shm@4.format(892420434)
[3432982.083] wl_shm@4.format(909199186)
[3432982.087] wl_shm@4.format(808665688)
[3432982.093] wl_shm@4.format(808665665)
[3432982.097] wl_shm@4.format(1211384408)
[3432982.101] wl_shm@4.format(1211384385)
[3432982.106] wl_shm@4.format(942948952)
[3432982.110] wl_shm@4.format(942948929)
[3432982.113] wl_seat@10.name("seat0")
[3432982.123] wl_seat@10.capabilities(2)
[3432982.131]  -> wl_data_device_manager@7.get_data_device(new id wl_data_device@12, wl_seat@10)
[3432982.141] wl_output@11.geometry(0, 0, 290, 180, 0, "California Institute of Technology", "0x076D", 0)
[3432982.151] wl_output@11.mode(1, 2560, 1600, 59994)
[3432982.156] wl_output@11.scale(2)
[3432982.161] wl_output@11.done()
[3432982.166] wl_callback@3.done(53878)
[3432982.177]  -> wl_registry@2.bind(45, "zwp_primary_selection_device_manager_v1", 1, new id [unknown]@3)
[3432982.189]  -> zwp_primary_selection_device_manager_v1@3.get_device(new id zwp_primary_selection_device_v1@13, wl_seat@10)
[3432982.202]  -> wl_seat@10.get_keyboard(new id wl_keyboard@14)
[3432982.213]  -> zwp_text_input_manager_v3@9.get_text_input(new id zwp_text_input_v3@15, wl_seat@10)
[3432982.256]  -> wl_shm@4.create_pool(new id wl_shm_pool@16, fd 5, 4096)
21:09:15.022  ERROR  env_bootstrap > panic at window/src/os/wayland/connection.rs:191:35 - called `Option::unwrap()` on a `None` value
   0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>
  10: <unknown>
  11: <unknown>
  12: <unknown>
  13: <unknown>
  14: <unknown>
  15: <unknown>
  16: <unknown>
  17: <unknown>
  18: __libc_start_main
  19: <unknown>

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', window/src/os/wayland/connection.rs:191:35
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[3432983.763]  -> wl_shm_pool@16.destroy()

@q234rty
Copy link

q234rty commented Feb 4, 2023

@glyh #3050 doesn't look like a duplicate of this considering that your WAYLAND_DEBUG=1 output doesn't include the "Buffer size is not divisible by scale" error.

@glyh
Copy link

glyh commented Feb 4, 2023

@q234rty Thank you I'm going to reopen the one.

hahuang65 added a commit to hahuang65/sway-config that referenced this issue Feb 11, 2023
@Omrigan
Copy link

Omrigan commented Mar 10, 2023

I see a slightly different error message. In my case, it usually happens some time after unplugging external display, so many instances of the wezterm get resized because of different resolutions.

[2962560.796] wl_display@1.error(wl_surface@131, 2, "Buffer size (1020x603) is not divisible by scale (2)")
wl_surface@131: error 2: Buffer size (1020x603) is not divisible by scale (2)
18:13:32.536  ERROR  wezterm_gui                            > running message loop: error during event_q.dispatch protocol_error=Some(ProtocolError { code: 2, object_id: 131, object_interface: "wl_surface", message: "" }): Protocol error (os error 71); terminating

More logs:

This is from Arch's wezterm-git
wezterm-error.log

This one is from stable release:
wezterm-old.log

@RAOF
Copy link
Contributor

RAOF commented Apr 11, 2023

So, looking at the logs when this happens it seems the sequence of events is:
window is created with a non-even dimension:

 -> buffer_create(@1, ..., 517, 36)
 -> surface@2.attach_buffer(1)
 -> surface@2.commit()

Now that the surface has content, the compositor maps the window and sends a wl_surface.enter event.
Wezterm responds by sending wl_surface.set_buffer_scale(2):

wl_surface@2.enter(wl_output@<id of some output with scale 2>)
  -> surface@2.set_buffer_scale(2)
  -> surface@2.commit()

At this point Wezterm has committed a 517×36 buffer with scale 2, and the compositor sends a protocol error.

This can also happen when moving a window from a scale-1 output to a scale-2 output; the wl_surface.enter() event triggers the same protocol error in the same way.

I've not traced the wezterm code, but I suspect that the wl_surface.enter handler needs to be changed to set a flag and trigger a refresh, and buffer scale should be set only immediately before committing a buffer.

(The crash on initial surface construction is kinda a consequence of this protocol bug - wezterm cannot know what buffer scale to use without first committing a buffer to the surface - but the solution is the same for both the initial creation and the move-to-different-output cases).

@jbiel
Copy link

jbiel commented May 9, 2023

This is easily reproducible on my laptop's screen (scaling 1.5) under latest sway etc. If I have a screen with one wezterm running and try to launch another one, they both crash. The workaround noted by @gfauredev works for me.

@kode54
Copy link

kode54 commented Jun 15, 2023

And now this is crashing on Gnome Shell 44.2, taking the entire Gnome Wayland session down with it.

@josecastillolema
Copy link

@gfauredev solution works!
It is possible to configure it in the wezterm config file as well:

default_gui_startup_args = {'start', '--always-new-process'}

@azzamsa
Copy link
Contributor

azzamsa commented Jan 11, 2024

@khamer
Copy link

khamer commented Feb 9, 2024

I can duplicate this on demand with the following steps, running sway:

  1. Open two instances of wezterm, stacked vertically.
  2. Open a third instance of wezterm so that all three should get 1/3 of the monitor.
  3. Watch wezterm crash.

wezterm.log
Another log from a similar but not identical set of events: log.txt

I also confirm changing my sway hotkey to pass --always-new-process as an argument to wezterm works around the issue.

@wildwestrom
Copy link

wildwestrom commented Feb 15, 2024

It seems like this issue was worked around in imv by this patch.

https://lists.sr.ht/~exec64/imv-devel/patches/38286

@@ [550](https://git.sr.ht/~exec64/imv/tree/4448fb6104d67e3dfff3e71babe257992fce5560/item/src/wl_window.c#L550),8 [550](https://git.sr.ht/~exec64/imv/tree/1817ef3df12a1c03d8642291eb7facd42c0f5580/item/src/wl_window.c#L550),6 @@ static void update_scale(struct imv_window *window)
   if (new_scale != window[-](https://git.sr.ht/~exec64/imv/commit/1817ef3#src/wl_window.c-1-4)>scale) {
     window[-](https://git.sr.ht/~exec64/imv/commit/1817ef3#src/wl_window.c-1-5)>scale = new_scale;
     wl_surface_set_buffer_scale(window->wl_surface, window->scale);
-    wl_surface_commit(window->wl_surface);
-    wl_display_roundtrip(window->wl_display);
     size_t buffer_width = window->width * window->scale;
     size_t buffer_height = window->height * window->scale;
     wl_egl_window_resize(window->egl_window, buffer_width, buffer_height, 0, 0);

There's another patch that seemed to help mpv work around this:
mpv-player/mpv@cd3b4ed

These could be helpful in fixing, though I don't know exactly where to edit the source in wezterm.

@wildwestrom
Copy link

wildwestrom commented Feb 15, 2024

Ok, I'm not Wayland expert but I've been reading, so here's my amateur assessment.

It seems like before a commit is made to a surface, the width and height must be divisible by the scale before a commit. This must mean the error occurs because a buffer that is not divisible by the scale has been committed, but why?

I'm think I have no choice but to set breakpoints on every commit and see what the state of the pending scale, width, and height are. Anyway, I'll have to revisit this another time, but I'll leave this here for future reference.

Here's a list of all the projects that have fixed this particular issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Wayland
Projects
None yet
Development

No branches or pull requests