Bug 247368 - Crash in gamepads in WKWebView apps that also listen to the GameController framework themselves
Summary: Crash in gamepads in WKWebView apps that also listen to the GameController fr...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: Safari 16
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Brady Eidson
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-11-02 09:22 PDT by Brady Eidson
Modified: 2022-11-02 16:28 PDT (History)
2 users (show)

See Also:


Attachments
Patch (1.92 KB, patch)
2022-11-02 10:05 PDT, Brady Eidson
ggaren: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brady Eidson 2022-11-02 09:22:40 PDT
Crash in gamepads in WKWebView apps that also listen to the GameController framework themselves

If an app's UI process uses GameController framework directly before a web page in a WKWebView does, then the GameController framework tells that app about attached controllers ahead of time.

This subtlely gets WebKit's notion of attached game controllers out of sync with reality.
If the user then moves a joystick on the gamepad to cause input (but not press a button to cause the gamepad to be exposed to the web page) then we crash. (And ASSERT in debug builds)
Comment 1 Brady Eidson 2022-11-02 10:05:12 PDT
Created attachment 463363 [details]
Patch
Comment 2 Brady Eidson 2022-11-02 10:35:06 PDT
<rdar://problem/100036005>
Comment 3 Geoffrey Garen 2022-11-02 10:38:13 PDT
Comment on attachment 463363 [details]
Patch

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

r=me

> Source/WebKit/UIProcess/Gamepad/UIGamepadProvider.cpp:118
> +    for (size_t i = 0; i < m_gamepads.size() && i < platformGamepads.size(); ++i) {

You can compute 'auto end = std::min(m_gamepads.size(), platformGamepads.size())' outside the loop. A bit clearer and a bit more efficient.
Comment 4 Brady Eidson 2022-11-02 15:03:15 PDT
Pull request: https://github.com/WebKit/WebKit/pull/6054
Comment 5 EWS 2022-11-02 16:28:53 PDT
Committed 256255@main (809586a6b81e): <https://commits.webkit.org/256255@main>

Reviewed commits have been landed. Closing PR #6054 and removing active labels.