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

Fixes accessibility issue that bridge fails to clean up FlutterScrollableSemanticsObject - #28495

Merged
fluttergithubbot merged 6 commits into
flutter-team-archive:masterfrom
chunhtai:issues/89613
Sep 10, 2021
Merged

fluttergithubbot merged 6 commits into
flutter-team-archive:masterfrom
chunhtai:issues/89613

Conversation

@chunhtai

@chunhtai chunhtai commented Sep 7, 2021

Copy link
Copy Markdown
Contributor

fixes flutter/flutter#89613

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@chunhtai chunhtai changed the title Issues/89613 Fixes accessibility issue that bridge fails to clean up FlutterScrollableSemanticsObject Sep 8, 2021
@chunhtai
chunhtai requested a review from gaaclarke September 8, 2021 19:17
Comment on lines +166 to +169
- (void)willRemoveFromAccessibilityBridge {
[self removeFromSuperview];
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

removeFromSuperview is called in the dealloc of the FlutterScrollableSemanticsObject, are these objects leaking, that's why they aren't getting removed from the superview? If so we should fix the leak instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it seems like the superview will hold a reference on this object. The object was never dealloc, so it just keeps adding more UIScrollable :D

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Makes sense, I think we should investigate what I've suggested in my last review before accepting this change.

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Alternatively, instead of making FlutterScrollableSemanticsObject subclass UIScrollView, it could have a UIScrollView. That way when the FlutterScrollableSemanticsObject is deleted, it can remove the UIScrollView from its superview (thus breaking the cycle).

That would be preferable because, while the solution you are proposing will work, it is much more costly to maintain than if everything just works with standard object memory management.

@chunhtai
chunhtai requested a review from gaaclarke September 9, 2021 19:31
@chunhtai

chunhtai commented Sep 9, 2021

Copy link
Copy Markdown
Contributor Author

existing test should cover the refactoring PTAL @gaaclarke

@chunhtai
chunhtai requested a review from gaaclarke September 9, 2021 22:35

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome, LGTM with the caveat that you've tested it locally too. Despite our work to improve the testing on this code it still makes me a bit nervous to change it.

@chunhtai

Copy link
Copy Markdown
Contributor Author

Awesome, LGTM with the caveat that you've tested it locally too. Despite our work to improve the testing on this code it still makes me a bit nervous to change it.

I have tested it locally. I think this is one step toward the right direction, and we just need to watch out for regression...

@chunhtai chunhtai added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Sep 10, 2021
@fluttergithubbot
fluttergithubbot merged commit 48ce284 into flutter-team-archive:master Sep 10, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 10, 2021
- (instancetype)initWithSemanticsObject:(SemanticsObject*)semanticsObject {
self = [super initWithFrame:CGRectZero];
if (self) {
_semanticsObject = semanticsObject;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe we're missing a retain here, which is the cause of a crash noted in flutter/flutter#92853

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It was not that we're missing a retain, but that we're missing niling this out when the parent object is deallocated.

uid:(int32_t)uid {
self = [super initWithBridge:bridge uid:uid];
if (self) {
_semanticsObject = [semanticsObject retain];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes. It used to live here.

@zjrwdl

zjrwdl commented May 27, 2022 •

Copy link
Copy Markdown

these commits have been merged in flutter 2.8 ,but this crash is also exist.

stack belows:

flutter::AccessibilityBridge::GetOrCreateObject(int, std::__1::unordered_map<int, flutter::SemanticsNode, std::__1::hash, std::__1::equal_to, std::__1::allocator<std::__1::pair<int const, flutter::SemanticsNode> > >&) (in Flutter) (accessibility_bridge.mm:303)
flutter::PlatformViewIOS::UpdateSemantics(std::__1::unordered_map<int, flutter::SemanticsNode, std::__1::hash, std::__1::equal_to, std::__1::allocator<std::__1::pair<int const, flutter::SemanticsNode> > >, std::__1::unordered_map<int, flutter::CustomAccessibilityAction, std::__1::hash, std::__1::equal_to, std::__1::allocator<std::__1::pair<int const, flutter::CustomAccessibilityAction> > >) (in Flutter) (platform_view_ios.mm:191)
std::__1::__function::__func<flutter::Shell::OnEngineUpdateSemantics(std::__1::unordered_map<int, flutter::SemanticsNode, std::__1::hash, std::__1::equal_to, std::__1::allocator<std::__1::pair<int const, flutter::SemanticsNode> > >, std::__1::unordered_map<int, flutter::CustomAccessibilityAction, std::__1::hash, std::__1::equal_to, std::__1::allocator<std::__1::pair<int const, flutter::CustomAccessibilityAction> > >)::$_38, std::__1::allocator<flutter::Shell::OnEngineUpdateSemantics(std::__1::unordered_map<int, flutter::SemanticsNode, std::__1::hash, std::__1::equal_to, std::__1::allocator<std::__1::pair<int const, flutter::SemanticsNode> > >, std::__1::unordered_map<int, flutter::CustomAccessibilityAction, std::__1::hash, std::__1::equal_to, std::__1::allocator<std::__1::pair<int const, flutter::CustomAccessibilityAction> > >)::$_38>, void ()>::operator()() (in Flutter) (functional:1720)
fml::MessageLoopImpl::FlushTasks(fml::FlushType) (in Flutter) (message_loop_impl.cc:132)
fml::MessageLoopDarwin::OnTimerFire(__CFRunLoopTimer*, fml::MessageLoopDarwin*) (in Flutter) (message_loop_darwin.mm:81)

@chunhtai

Copy link
Copy Markdown
Contributor Author

@zjrwdl if you are still seeing the same crash it may be a different cause, can you file a new issue with repro steps?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes platform-ios waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.

Development

Successfully merging this pull request may close these issues.

[A11y] iOS accessibility bridge does not clean up FlutterScrollableSemanticsObject

5 participants