diff --git a/src/wayland/buffer/manager.cpp b/src/wayland/buffer/manager.cpp index 6bbdf292..713752ab 100644 --- a/src/wayland/buffer/manager.cpp +++ b/src/wayland/buffer/manager.cpp @@ -69,6 +69,11 @@ bool WlBufferManager::isReady() const { return this->p->mReady; } qCDebug(logBuffer) << " Format" << format; } + if (request.width == 0 || request.height == 0) { + qCWarning(logBuffer) << "Cannot create zero-sized buffer."; + return nullptr; + } + if (!dmabufDisabled) { if (auto* buf = this->p->dmabuf.createDmabuf(request)) return buf; qCWarning(logBuffer) << "DMA buffer creation failed, falling back to SHM."; diff --git a/src/wayland/screencopy/hyprland_screencopy/hyprland_screencopy.cpp b/src/wayland/screencopy/hyprland_screencopy/hyprland_screencopy.cpp index 5268f665..6fc29558 100644 --- a/src/wayland/screencopy/hyprland_screencopy/hyprland_screencopy.cpp +++ b/src/wayland/screencopy/hyprland_screencopy/hyprland_screencopy.cpp @@ -103,6 +103,16 @@ void HyprlandScreencopyContext::hyprland_toplevel_export_frame_v1_flags(uint32_t void HyprlandScreencopyContext::hyprland_toplevel_export_frame_v1_buffer_done() { auto* backbuffer = this->mSwapchain.createBackbuffer(this->request); + + if (!backbuffer || !backbuffer->buffer()) { + qCWarning(logScreencopy) << "Backbuffer creation failed for screencopy. Skipping frame."; + + // Try again. This will be spammy if the compositor continuously sends bad frames. + this->destroy(); + this->captureFrame(); + return; + } + this->copy(backbuffer->buffer(), this->copiedFirstFrame ? 0 : 1); } diff --git a/src/wayland/screencopy/image_copy_capture/image_copy_capture.cpp b/src/wayland/screencopy/image_copy_capture/image_copy_capture.cpp index a307d1ee..13d1bc6d 100644 --- a/src/wayland/screencopy/image_copy_capture/image_copy_capture.cpp +++ b/src/wayland/screencopy/image_copy_capture/image_copy_capture.cpp @@ -117,6 +117,12 @@ void IccScreencopyContext::doCapture() { auto newBuffer = false; auto* backbuffer = this->mSwapchain.createBackbuffer(this->request, &newBuffer); + if (!backbuffer || !backbuffer->buffer()) { + qCWarning(logIcc) << "Backbuffer creation failed for screencopy. Waiting for updated buffer " + "creation parameters before trying again."; + return; + } + this->IccCaptureFrame::init(this->IccCaptureSession::create_frame()); this->IccCaptureFrame::attach_buffer(backbuffer->buffer()); diff --git a/src/wayland/screencopy/wlr_screencopy/wlr_screencopy.cpp b/src/wayland/screencopy/wlr_screencopy/wlr_screencopy.cpp index c7a11a70..e1553f51 100644 --- a/src/wayland/screencopy/wlr_screencopy/wlr_screencopy.cpp +++ b/src/wayland/screencopy/wlr_screencopy/wlr_screencopy.cpp @@ -111,6 +111,15 @@ void WlrScreencopyContext::zwlr_screencopy_frame_v1_flags(uint32_t flags) { void WlrScreencopyContext::zwlr_screencopy_frame_v1_buffer_done() { auto* backbuffer = this->mSwapchain.createBackbuffer(this->request); + if (!backbuffer || !backbuffer->buffer()) { + qCWarning(logScreencopy) << "Backbuffer creation failed for screencopy. Skipping frame."; + + // Try again. This will be spammy if the compositor continuously sends bad frames. + this->destroy(); + this->captureFrame(); + return; + } + if (this->copiedFirstFrame) { this->copy_with_damage(backbuffer->buffer()); } else {