Skip to content

image-copy: Raise the duplicate_frame protocol error - #2185

Merged
Drakulix merged 1 commit into
Smithay:masterfrom
Netflate:fix/image-copy-duplicate-frame
Sep 30, 2026
Merged

Drakulix merged 1 commit into
Smithay:masterfrom
Netflate:fix/image-copy-duplicate-frame

Conversation

@Netflate

Copy link
Copy Markdown

Description

create_frame should not create an active frame when one already exists. ext_image_copy_capture_session_v1 already defines an error for this (duplicate_frame) but it was never raised.

Refuse to create a second frame while session still has an active one. Checking if active_frames is empty or not is accurate since the frame's destroyed() already removes it from the session.

From the protocol:

      <description summary="create a frame">
        Create a capture frame for this session.

        At most one frame object can exist for a given session at any time. If
        a client sends a create_frame request before a previous frame object
        has been destroyed, the duplicate_frame protocol error is raised.
      </description>

Tested with an ext-image-copy-capture client that calls create_frame twice without destroying the first one:

Before, the second request is accepted silently:

-> ext_image_copy_capture_session_v1@41.create_frame(ext_image_copy_capture_frame_v1@46)
-> ext_image_copy_capture_session_v1@41.create_frame(ext_image_copy_capture_frame_v1@47)

After:

-> ext_image_copy_capture_session_v1@34.create_frame(ext_image_copy_capture_frame_v1@39)
-> ext_image_copy_capture_session_v1@34.create_frame(ext_image_copy_capture_frame_v1@40)
<- wl_display@1.error, (34, 1, Some("create_frame sent before the previous frame was destroyed"))

(Reported downstream in pop-os/cosmic-comp#2279.)

Checklist

@HigherOrderLogic HigherOrderLogic left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems correct to me.

Comment thread src/wayland/image_copy_capture/mod.rs Outdated
@Netflate
Netflate force-pushed the fix/image-copy-duplicate-frame branch from 0fcd367 to 4cdf1e9 Compare September 28, 2026 16:04

@Drakulix Drakulix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for tackling this, couple of comments

Comment thread src/wayland/image_copy_capture/mod.rs Outdated
.unwrap()
.active_frames
.push(FrameRef { obj, inner });
if !self.inner.lock().unwrap().active_frames.is_empty() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, if only one frame can exist at a time, active_frames should be changed to an Option called active_frame.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

re-tested to be sure, behavior is unchanged. The first create_frame is accepted and the second one raises the error

Comment thread src/wayland/image_copy_capture/mod.rs Outdated
ext_image_copy_capture_session_v1::Error::DuplicateFrame,
"create_frame sent before the previous frame was destroyed",
);
} else {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please just add a return to the if branch and remove the else. We can avoid the indentation here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread src/wayland/image_copy_capture/mod.rs Outdated
.unwrap()
.active_frames
.push(FrameRef { obj, inner });
if !self.inner.lock().unwrap().active_frames.is_empty() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

`create_frame` should not create an active frame when one already exists.
`ext_image_copy_capture_session_v1` defines an error for this (`duplicate_frame`)
but it is never raised.

Refuse to create a second frame while the session still has an active one.

Signed-off-by: Netflate <netflate@gmail.com>
@Netflate
Netflate force-pushed the fix/image-copy-duplicate-frame branch from 4cdf1e9 to 745b774 Compare September 29, 2026 20:49

@Drakulix Drakulix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now. Thanks!

@Drakulix
Drakulix merged commit 5ed5986 into Smithay:master Sep 30, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants