Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wl: Check wl_surface before use it #669

Merged
merged 1 commit into from
Nov 23, 2023

Conversation

psaavedra
Copy link
Member

... on pointer_on_enter, touch_on_down and keyboard_on_enter.

It can be possible a situation during the destruction of a CogView where the UI-process were receiving and trying to process an input event for a non existant wl_surface.

Under this scenario, the wl_surface associated could be not longer accesible so the input handler will receive a null-pointer (0x0).

Backtrace:

0  0xb9999999 in wl_proxy_get_user_data (proxy=proxy@entry=0x0)
    at ../wayland/src/wayland-client.c:2135

    at /usr/include/wayland-client-protocol.h:3393
    fixed_x=0, fixed_y=5, surface=0x0 <<<< , data=0xa9999999)

@psaavedra psaavedra self-assigned this Nov 23, 2023
@psaavedra psaavedra requested a review from aperezdc November 23, 2023 01:00
@aperezdc aperezdc added the bug Something isn't working label Nov 23, 2023
Copy link
Member

@aperezdc aperezdc left a comment

Choose a reason for hiding this comment

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

This fix is not 100% ideal: compositors are not allowed to pass NULL surfaces for these events, because the protocol definition does not have the allow-null="true" attribute for the surface parameter.

In theory we should read pending events before destroying surfaces, to ensure we don't have any left for them, but in practice that fix would be more complicated. Also, I have seen similar fixes in other projects (like glfw/glfw#1191) so I think we can go with the approach suggested in this PR for now.

Please remove the g_warning() calls before merging, though.

platform/wayland/cog-platform-wl.c Outdated Show resolved Hide resolved
platform/wayland/cog-platform-wl.c Outdated Show resolved Hide resolved
platform/wayland/cog-platform-wl.c Outdated Show resolved Hide resolved
@psaavedra
Copy link
Member Author

This fix is not 100% ideal: compositors are not allowed to pass NULL surfaces for these events, because the protocol definition does not have the allow-null="true" attribute for the surface parameter.

In theory we should read pending events before destroying surfaces, to ensure we don't have any left for them,

Yes, for this reason I am handling this with a warning message because, to me,it is like a buggy implementation is the Wayland compositor more like an issue in the Cog side.

but in practice that fix would be more complicated. Also, I have seen similar fixes in other projects (like glfw/glfw#1191) so I think we can go with the approach suggested in this PR for now.

Please remove the g_warning() calls before merging, though.

One idea it could handle this with a listener for the wl_surface destruction

struct wl_surface_listener my_surface_listener = {
    // Callback on wl_surface destroy
    .destroy = wl_surface_on_destroy,
};

but the key here is that the pointer|touch|... event handlers are actually associated to the Wayland Seat and we are using the same handlers for all the wl_surfaces from different Views. Actually we rely on the wl_surface object passed as argument to get the CogView attached to it.

@aperezdc
Copy link
Member

@psaavedra I think it's not worth it to bother with the destroy listener, let's merge this as-is.

Maybe changing warnings into a comment—but I won't insist much on it. IMO there is nothing wrong with deciding that our code handles the NULLs instead of doing something more complicated, so I think there is no point in warning the user.

... on pointer_on_enter, touch_on_down and keyboard_on_enter.

It can be possible a situation during the destruction of a CogView
where the UI-process were receiving and trying to process an input
event for a non existant wl_surface.

Under this scenario, the wl_surface associated could be not longer
accesible so the input handler will receive a null-pointer (0x0).

Backtrace:

```
0  0xb9999999 in wl_proxy_get_user_data (proxy=proxy@entry=0x0)
    at ../wayland/src/wayland-client.c:2135

    at /usr/include/wayland-client-protocol.h:3393
    fixed_x=0, fixed_y=5, surface=0x0 <<<< , data=0xa9999999)
```
@psaavedra psaavedra force-pushed the psaavedra/check_wl_surface_before_use_it branch from 3369bd2 to c13ffe9 Compare November 23, 2023 15:03
@psaavedra
Copy link
Member Author

@psaavedra I think it's not worth it to bother with the destroy listener, let's merge this as-is.

Maybe changing warnings into a comment—but I won't insist much on it. IMO there is nothing wrong with deciding that our code handles the NULLs instead of doing something more complicated, so I think there is no point in warning the user.

OK. Let's do it then.

@psaavedra psaavedra merged commit 882c1ef into master Nov 23, 2023
5 checks passed
@psaavedra psaavedra deleted the psaavedra/check_wl_surface_before_use_it branch November 23, 2023 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants