Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Guard against orphaned semantic objects from referencing dead accessibility bridge on iOS#13857

Merged
darrenaustin merged 3 commits intoflutter:masterfrom
darrenaustin:orphaned_semantics
Nov 14, 2019
Merged

Guard against orphaned semantic objects from referencing dead accessibility bridge on iOS#13857
darrenaustin merged 3 commits intoflutter:masterfrom
darrenaustin:orphaned_semantics

Conversation

@darrenaustin
Copy link
Contributor

The core issue causing flutter/flutter#43795 is that when VoiceOver is turned off, it will still hang onto our SemanticObjects for the focused node. In response to VoiceOver shutting down (via the UIAccessibilityVoiceOverStatusChanged message handler), we tear down the AccessibilityBridge. When this happens we release all of our SemanticsObjects and delete the bridge. However, because iOS will hold onto (at least in this case) the focused semantics object, when VoiceOver is turned back on it will notify the the semantic object that it no longer has focus. If the node tries to do anything that involves the bridge, it will try to dereference a dead weak pointer, so it crashes.

I attempted several approaches to see if there was a way to get iOS to release the node (reseting the semantics tree to empty, sending various UIAccessibilityPostNotification messages), but nothing would cause it to release the now defunct SemanticsObject.

I looked into wrapping each of the SemanticsObjects with a safe guarding object that would only delegate to the real semantics object if the bridge were still active. This would be way more boilerplate than it would be worth (in addition to adding to taking up more memory for each node).

So the solution I came up with is this. I added a new macro RETURN_IF_ORPHANED that can be used at the top of any accessibility message handler in a SemanticsObject. It will check if the node's bridge is still active and if not, then just return immediately. This will guard against any references to a dead bridge. Not the most elegant solution, and I am open to better suggestions. Are there any similar patterns in use in the engine?

Fixes: flutter/flutter#43795

Copy link
Contributor

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

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

There is a pretty strong preference against preprocessor macros in the style guide. The pattern looks fine but I am in favor of just moving this to a method (say -[SemnticsObject isAccessibilityBridgeAlive]) with the same documentation and have the methods return the appropriate zeroed return value in case of the negative response.

@darrenaustin
Copy link
Contributor Author

Thanks for the feedback. Yeah, I am usually not a fan of macros either, but in this case I was trying to minimize the boilerplate. My first pass was exactly what you are suggesting. I will switch it back.

@darrenaustin darrenaustin merged commit 5b10fa3 into flutter:master Nov 14, 2019
@darrenaustin darrenaustin deleted the orphaned_semantics branch November 14, 2019 20:16
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 14, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 14, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 15, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 15, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 15, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 15, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 15, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 15, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 15, 2019
flar pushed a commit to flutter/flutter that referenced this pull request Nov 15, 2019
* 174e0e9 Roll src/third_party/dart dc35290111..dc808f3fcb (5 commits) (flutter/engine#13859)

* 33d997c Roll fuchsia/sdk/core/mac-amd64 from 7XOyl... to VMTIz... (flutter/engine#13861)

* b4899d9 Roll src/third_party/skia d860a78fd60c..e57ca4931952 (44 commits) (flutter/engine#13862)

* f456423 RendererContextSwitch guard flutter's gl context rework. (flutter/engine#13812)

* 6bab64e Fix test to account for pixel ratio transformations being framework responsibility. (flutter/engine#13850)

* 5b10fa3 Guard against orphaned semantic objects from referencing dead accessibility bridge on iOS (flutter/engine#13857)

* 97df087 [fuchsia] Package flutter_frontend_server snapshot for fuchsia (flutter/engine#13865)

* 0832dfd [flow][fuchsia] Add more tracing to layers and Fuchsia surface pool (flutter/engine#13864)

* 141dc785d Roll src/third_party/skia e57ca4931952..c1c4634dcb07 (15 commits) (flutter/engine#13866)

* 90a6054 Revert "Roll src/third_party/dart dc35290111..dc808f3fcb (5 commits) (#13859)" (flutter/engine#13867)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextField toggle a11y off/on crashes on iOS

3 participants