Bug 506412 - A protocol error "xdg_surface must not have a buffer at creation" occurs with a null buffer attached to the surface
Summary: A protocol error "xdg_surface must not have a buffer at creation" occurs with...
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: wayland-generic (other bugs)
Version First Reported In: 6.4.1
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-06-30 21:34 UTC by Frank Praznik
Modified: 2025-07-04 18:59 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 6.4.3
Sentry Crash Report:


Attachments
Full WAYLAND_DEBUG=1 output (2.65 MB, text/plain)
2025-06-30 21:34 UTC, Frank Praznik
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Frank Praznik 2025-06-30 21:34:31 UTC
Created attachment 182816 [details]
Full WAYLAND_DEBUG=1 output

SUMMARY
The protocol error "xdg_wm_base#29: error 3: xdg_surface must not have a buffer at creation" occurs when attempting to create an xdg_surface while mapping a window on KDE, even though a null buffer is attached and committed to the surface at the time of creation.

STEPS TO REPRODUCE
1. Clone the reproducer from https://github.com/kontrabant/SDL.git
2. Switch to the xdg_configure_test branch
3. Build with the cmake option -DSDL_TESTS=ON
4. Run the testsprite demo with "SDL_RENDER_DRIVER=vulkan ./testsprite"
5. The window will automatically hide and show, and the issue should quickly occur. I've only seen this on the Mesa AMD and Intel Vulkan drivers, llvmpipe doesn't seem to exhibit the issue (unsure about the proprietary Nvidia drivers).

OBSERVED RESULT

The program halts with the protocol error "xdg_wm_base#29: error 3: xdg_surface must not have a buffer at creation" while mapping the window.

Relevant bits of the WAYLAND_DEBUG=1 log:
```
[2487569.784] {mesa vk display queue}  -> wp_linux_drm_syncobj_surface_v1#58.set_acquire_point(wp_linux_drm_syncobj_timeline_v1#74, 0, 918)
[2487569.813] {mesa vk display queue}  -> wp_linux_drm_syncobj_surface_v1#58.set_release_point(wp_linux_drm_syncobj_timeline_v1#75, 0, 918)
[2487569.821] {mesa vk display queue}  -> wl_surface#3.attach(wl_buffer#73, 0, 0)
[2487569.826] {mesa vk display queue}  -> wl_surface#3.damage(0, 0, 2147483647, 2147483647)
[2487569.831] {mesa vk display queue}  -> wl_surface#3.commit()
[2487569.838] {mesa vk display queue} discarded wl_buffer#65.release()
[2487569.899] {Default Queue}  -> wl_display#1.sync(new id wl_callback#60)
[2487569.971] {Display Queue} wl_display#1.delete_id(60)
[2487569.980] {Default Queue} wl_callback#60.done(8867)
[2487570.001] {Default Queue}  -> wl_surface#3.attach(nil, 0, 0)
[2487570.006] {Default Queue}  -> wl_surface#3.commit()
[2487570.011] {Default Queue}  -> xdg_wm_base#29.get_xdg_surface(new id xdg_surface#60, wl_surface#3)
[2487570.019] {Default Queue}  -> xdg_surface#60.get_toplevel(new id xdg_toplevel#80)
[2487570.025] {Default Queue}  -> xdg_toplevel#80.set_app_id("testsprite")
[2487570.030] {Default Queue}  -> zxdg_decoration_manager_v1#7.get_toplevel_decoration(new id zxdg_toplevel_decoration_v1#81, xdg_toplevel#80)
[2487570.038] {Default Queue}  -> zxdg_toplevel_decoration_v1#81.set_mode(2)
[2487570.043] {Default Queue}  -> zxdg_exporter_v2#22.export_toplevel(new id zxdg_exported_v2#72, wl_surface#3)
[2487570.049] {Default Queue}  -> xdg_toplevel#80.set_parent(nil)
[2487570.054] {Default Queue}  -> xdg_toplevel#80.set_title("./test/testsprite")
[2487570.059] {Default Queue}  -> wl_surface#3.commit()
[2487570.193] {Display Queue} wl_display#1.error(xdg_wm_base#29, 3, "xdg_surface must not have a buffer at creation")
xdg_wm_base#29: error 3: xdg_surface must not have a buffer at creation
```

EXPECTED RESULT

The example program maps the window and runs normally.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Fedora 42
KDE Plasma Version: 6.4.1
KDE Frameworks Version: 6.15.0
Qt Version: 6.9.1

ADDITIONAL INFORMATION

I can run the reproducer for long periods of time on GNOME, Weston, and Sway under the same conditions with no issues, so this is KDE specific.
Comment 1 Bug Janitor Service 2025-06-30 22:33:40 UTC
Thank you for the bug report!

However Plasma 6.1.1 is no longer eligible for support or maintenance from KDE; supported versions are 5.27. (LTS), and 6.3 (non-LTS) or newer. Please upgrade to a supported version as soon as your distribution makes it available to you. Plasma is a fast-moving project, and bugs in one version are often fixed in the next one.

If you need support for Plasma 6.1.1, please contact your distribution, who bears the responsibility of providing support for older releases that are no longer supported by KDE.

If you can reproduce the issue after upgrading to a supported version, feel free to re-open this bug report.
Comment 2 Frank Praznik 2025-07-03 18:14:31 UTC
I'm fairly certain this is caused by a race condition now, because if I add a sleep of just 1 millisecond in between attaching/committing the null buffer to the wl_surface and (re)creating the xdg_surface, it runs correctly.
Comment 3 Zamundaaa 2025-07-04 14:44:00 UTC
Can confirm.
Comment 4 Bug Janitor Service 2025-07-04 15:13:52 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/7873
Comment 5 Zamundaaa 2025-07-04 16:11:44 UTC
Git commit 7772926af7f74e29c14f7b97418745111278dd83 by Xaver Hugl, on behalf of Vlad Zahorodnii.
Committed on 04/07/2025 at 15:43.
Pushed by zamundaaa into branch 'master'.

wayland: Remove buffer checks in xdg_surface and layer_surface factory requests

Due to transactions getting delayed sometimes, the current surface state
may have a buffer. It doesn't necessarily mean that it's a protocol error.

Whether the client has actually committed an invalid state will be
determined later when the client commits the surface after creating the
surface role.

M  +0    -5    src/wayland/layershell_v1.cpp
M  +0    -5    src/wayland/xdgshell.cpp

https://invent.kde.org/plasma/kwin/-/commit/7772926af7f74e29c14f7b97418745111278dd83
Comment 6 Zamundaaa 2025-07-04 18:59:32 UTC
Git commit 225e73606c4bfcf0385d5c8664d2d086c930195a by Xaver Hugl, on behalf of Xaver Hugl.
Committed on 04/07/2025 at 16:21.
Pushed by zamundaaa into branch 'Plasma/6.4'.

wayland: Remove buffer checks in xdg_surface and layer_surface factory requests

Due to transactions getting delayed sometimes, the current surface state
may have a buffer. It doesn't necessarily mean that it's a protocol error.

Whether the client has actually committed an invalid state will be
determined later when the client commits the surface after creating the
surface role.


(cherry picked from commit 7772926af7f74e29c14f7b97418745111278dd83)

Co-authored-by: Vlad Zahorodnii <vlad.zahorodnii@kde.org>

M  +0    -5    src/wayland/layershell_v1.cpp
M  +0    -5    src/wayland/xdgshell.cpp

https://invent.kde.org/plasma/kwin/-/commit/225e73606c4bfcf0385d5c8664d2d086c930195a