wayland/screencopy: handle buffer creation failures

This commit is contained in:
outfoxxed 2025-07-26 00:48:21 -07:00
parent ab096b7e78
commit 91c9db581e
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
4 changed files with 30 additions and 0 deletions

View file

@ -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.";

View file

@ -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);
}

View file

@ -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());

View file

@ -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 {