Bug 231482 - [WebXR] Replace the session reference in WebXRSpace subclasses with weak pointers
Summary: [WebXR] Replace the session reference in WebXRSpace subclasses with weak poin...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Dean Jackson
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-10-09 15:15 PDT by Dean Jackson
Modified: 2021-10-10 16:05 PDT (History)
2 users (show)

See Also:


Attachments
Patch (18.19 KB, patch)
2021-10-09 15:22 PDT, Dean Jackson
sam: review+
Details | Formatted Diff | Diff
EWS test (22.33 KB, patch)
2021-10-10 11:33 PDT, Dean Jackson
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dean Jackson 2021-10-09 15:15:24 PDT
[WebXR] Replace the session reference in WebXRSpace subclasses with weak pointers
Comment 1 Dean Jackson 2021-10-09 15:22:06 PDT
Created attachment 440718 [details]
Patch
Comment 2 Radar WebKit Bug Importer 2021-10-09 15:37:43 PDT
<rdar://problem/84066341>
Comment 3 Sam Weinig 2021-10-09 17:39:18 PDT
Comment on attachment 440718 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=440718&action=review

> Source/WebCore/ChangeLog:12
> +        WebXRSpace had a pure virtual session() accessor that returned
> +        a reference to a WebXRSession. This made subclasses hold strong
> +        references to the WebXRSession, and would become problematic
> +        for a WebXRSpace subclass that was (indirectly) owned by the
> +        WebXRSession (found in the Hand Input module).

Pretty sure this was already causing leaks elsewhere for other XRSpaces, like the targetRaySpace and gripSpace in WebXRInputSource.

> Source/WebCore/Modules/webxr/WebXRReferenceSpace.cpp:72
> +    if (!m_session)
> +        return identity;

This feels a bit weird to me. It at least needs a comment explaining itself, but I would assume this would propagate an Exception to the caller.

> Source/WebCore/Modules/webxr/WebXRReferenceSpace.cpp:120
> +    if (!m_session)
> +        return { };

Same as above.

> Source/WebCore/Modules/webxr/WebXRSpace.cpp:61
> +    WebXRSession* xrSession = session();
> +    if (!xrSession)
> +        return false;

Seems like this should be an exception rather than just returning false.
Comment 4 Dean Jackson 2021-10-10 11:33:50 PDT
Created attachment 440732 [details]
EWS test
Comment 5 Dean Jackson 2021-10-10 11:35:13 PDT
Comment on attachment 440718 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=440718&action=review

>> Source/WebCore/Modules/webxr/WebXRReferenceSpace.cpp:72
>> +        return identity;
> 
> This feels a bit weird to me. It at least needs a comment explaining itself, but I would assume this would propagate an Exception to the caller.

Good point. I changed ::nativeOrigin to return an optional<TransformationMatrix>, updated all the subclasses, and return an Exception at the calling site if the session has disappeared.

>> Source/WebCore/Modules/webxr/WebXRReferenceSpace.cpp:120
>> +        return { };
> 
> Same as above.

Ditto.

>> Source/WebCore/Modules/webxr/WebXRSpace.cpp:61
>> +        return false;
> 
> Seems like this should be an exception rather than just returning false.

Done. Similar solution - this returns an optional that ends up returning an exception in the caller.
Comment 6 Dean Jackson 2021-10-10 16:05:27 PDT
Committed r283880 (242757@main): <https://commits.webkit.org/242757@main>