Skip to content

SIGSEGV in CWaylandBuffer when the swapchain cannot allocate a buffer (resizeSwapchain ignores failure) #144

Closed

Description

@erickbatistaprado

What happens

When the swapchain cannot allocate buffers, IWaylandWindow::resizeSwapchain() still
wraps swapchain->next(nullptr) in a CWaylandBuffer. next() returns null and the
CWaylandBuffer constructor dereferences it, so every hyprtoolkit app (here hyprpaper)
segfaults on its first configure instead of failing cleanly.

src/window/IWaylandWindow.cpp (same on v0.6.0 and current main):

m_waylandState.swapchain->reconfigure(Aquamarine::SSwapchainOptions{ ... });   // return value ignored

for (size_t i = 0; i < m_waylandState.wlBuffers.size(); ++i) {
    m_waylandState.wlBuffers[i] = makeShared<CWaylandBuffer>(m_waylandState.swapchain->next(nullptr));  // next() is null here
}

onPreRender() already returns early when wlBuffers[0]/[1] are null, so checking the
reconfigure() result / the buffer from next() and leaving the slot empty (and logging)
would avoid the crash.

How to reproduce

A QEMU/KVM guest with -vga virtio and no 3D acceleration (no virgl), so Mesa falls back
to kms_swrast. Inside a Hyprland session, a minimal config:

splash = false
wallpaper {
    monitor =
    path = /path/to/any/image.png
    fit_mode = cover
}

hyprpaper -c min.conf crashes every time:

ERR from hyprtoolkit ]: [EGL] Command eglInitialize errored out with EGL_NOT_INITIALIZED (0x12289): DRI2: failed to create screen
MESA-EGL: warning: NEEDS EXTENSION: falling back to kms_swrast
DEBUG ]: Found 1 output(s)
KMS: DRM_IOCTL_MODE_CREATE_DUMB failed: Permission denied
ERR from aquamarine ]: GBM: Allocating with modifiers failed, falling back to modifier-less allocation
KMS: DRM_IOCTL_MODE_CREATE_DUMB failed: Permission denied
ERR from aquamarine ]: GBM: Failed to allocate a GBM buffer: bo null
ERR from aquamarine ]: Couldn't allocate a gbm buffer with size [Vector2D: x: 1280, y: 800] and format XR24
ERR from aquamarine ]: Swapchain: Failed acquiring a buffer
Segmentation fault (core dumped)

Backtrace (systemd-coredump):

#0 Hyprtoolkit::CWaylandBuffer::CWaylandBuffer(Hyprutils::Memory::CSharedPointer<Aquamarine::IBuffer>) (libhyprtoolkit.so.6)
#1 Hyprtoolkit::IWaylandWindow::resizeSwapchain(Hyprutils::Math::Vector2D const&) (libhyprtoolkit.so.6)
#2 Hyprtoolkit::IWaylandWindow::configure(Hyprutils::Math::Vector2D const&, unsigned int) (libhyprtoolkit.so.6)
#3 (libhyprtoolkit.so.6)
#4 (hyprpaper)
#5-#7 libffi
#8-#10 libwayland-client (wl_display_dispatch_queue_pending)
#11 Hyprtoolkit::CBackend::dispatchWayland(...)
...
#16 Hyprtoolkit::CBackend::enterLoop()

Hyprland itself, Qt/Quickshell and GTK apps render fine in the same guest (Mesa llvmpipe).

Versions (Arch Linux packages)

  • hyprtoolkit 0.6.0
  • hyprpaper 0.8.4
  • aquamarine 0.15.1
  • hyprutils 0.14.3
  • hyprgraphics 0.5.1
  • Hyprland 0.57.0
  • mesa 26.2.6
  • wayland 1.26.0
  • kernel 7.2.11, QEMU -vga virtio (Virtio 1.0 GPU), no virgl

Related but different: #129 (RASSERT when drmFD is -1). This one is a null buffer after
the swapchain fails to allocate.

Separately from the crash: it would be great if hyprtoolkit could fall back to wl_shm
buffers when GBM/dumb allocation is unavailable, so wallpaper tools keep working in
VMs without 3D acceleration.

Activity

  1. UncleJ4ck commented on Nov 9, 2026

    @UncleJ4ck
    Contributor

    opened #155 with your fix. couldn't hit the alloc failure on real hardware here (gpu allocates fine), so it's compile-tested plus the normal path is untouched (the new branch only runs when next() is null). a confirm from the kms_swrast guest would seal it.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions