Skip to content

Commit 91c9db5

Browse files
committed
wayland/screencopy: handle buffer creation failures
1 parent ab096b7 commit 91c9db5

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

src/wayland/buffer/manager.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ bool WlBufferManager::isReady() const { return this->p->mReady; }
6969
qCDebug(logBuffer) << " Format" << format;
7070
}
7171

72+
if (request.width == 0 || request.height == 0) {
73+
qCWarning(logBuffer) << "Cannot create zero-sized buffer.";
74+
return nullptr;
75+
}
76+
7277
if (!dmabufDisabled) {
7378
if (auto* buf = this->p->dmabuf.createDmabuf(request)) return buf;
7479
qCWarning(logBuffer) << "DMA buffer creation failed, falling back to SHM.";

src/wayland/screencopy/hyprland_screencopy/hyprland_screencopy.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,16 @@ void HyprlandScreencopyContext::hyprland_toplevel_export_frame_v1_flags(uint32_t
103103

104104
void HyprlandScreencopyContext::hyprland_toplevel_export_frame_v1_buffer_done() {
105105
auto* backbuffer = this->mSwapchain.createBackbuffer(this->request);
106+
107+
if (!backbuffer || !backbuffer->buffer()) {
108+
qCWarning(logScreencopy) << "Backbuffer creation failed for screencopy. Skipping frame.";
109+
110+
// Try again. This will be spammy if the compositor continuously sends bad frames.
111+
this->destroy();
112+
this->captureFrame();
113+
return;
114+
}
115+
106116
this->copy(backbuffer->buffer(), this->copiedFirstFrame ? 0 : 1);
107117
}
108118

src/wayland/screencopy/image_copy_capture/image_copy_capture.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ void IccScreencopyContext::doCapture() {
117117
auto newBuffer = false;
118118
auto* backbuffer = this->mSwapchain.createBackbuffer(this->request, &newBuffer);
119119

120+
if (!backbuffer || !backbuffer->buffer()) {
121+
qCWarning(logIcc) << "Backbuffer creation failed for screencopy. Waiting for updated buffer "
122+
"creation parameters before trying again.";
123+
return;
124+
}
125+
120126
this->IccCaptureFrame::init(this->IccCaptureSession::create_frame());
121127
this->IccCaptureFrame::attach_buffer(backbuffer->buffer());
122128

src/wayland/screencopy/wlr_screencopy/wlr_screencopy.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ void WlrScreencopyContext::zwlr_screencopy_frame_v1_flags(uint32_t flags) {
111111
void WlrScreencopyContext::zwlr_screencopy_frame_v1_buffer_done() {
112112
auto* backbuffer = this->mSwapchain.createBackbuffer(this->request);
113113

114+
if (!backbuffer || !backbuffer->buffer()) {
115+
qCWarning(logScreencopy) << "Backbuffer creation failed for screencopy. Skipping frame.";
116+
117+
// Try again. This will be spammy if the compositor continuously sends bad frames.
118+
this->destroy();
119+
this->captureFrame();
120+
return;
121+
}
122+
114123
if (this->copiedFirstFrame) {
115124
this->copy_with_damage(backbuffer->buffer());
116125
} else {

0 commit comments

Comments
 (0)