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

Conversation

@chunhtai
Copy link
Contributor

@chunhtai chunhtai commented Mar 3, 2021

The inputview is created without anyone retaining, it work prior to this pr because the inputview was never detached from the flutterview, so the flutter view retains one reference.

My previous commit b3a18f5 detaches the inputview when user hides it, this makes it to be gc'd. This causes _activeView hold an invalid pointer.

fixes flutter/flutter#77139

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.
  • The reviewer has submitted any presubmit flakes in this PR using the engine presubmit flakes form before re-triggering the failure.

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

@flutter-dashboard

This comment has been minimized.

@chunhtai

This comment has been minimized.

@chunhtai

This comment has been minimized.

@chunhtai
Copy link
Contributor Author

Hi @gaaclarke I manage to write a mrc test to test the retaining count. I feel the test is quite fragile, but this is the only thing i can come up with. Can you take a look at this PR?

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

The fix looks good. I think the easiest way to test this would be to make an ARC test, then get a weak pointer to _activeView and assert that it does or does not get nil'd out to zero. Remember in ARC it will automatically set weak references to nil.

Something like this:

FlutterTextInputPlugin* plugin = [[FlutterTextInputPlugin alloc] init];
__weak UIView* activeView;
__weak UIView* oldActiveView;
@autoreleasepool {
  UIView* newActiveView = [[UIView alloc] init];
  activeView = newActiveView;
  oldActiveView = plugin.activeView;
  [plugin doSomethingThatReplacesTheActiveView:newActiveView];  
}
// This assert proves that the plugin retained the newActiveView.
XCTAssertNotNil(activeView);
// This assert proves we released the old active view.
XCTAssertNil(oldActiveView);

@chunhtai
Copy link
Contributor Author

@gaaclarke ahhhh nice! thanks for the suggestion, it does capture the failure prior to this change. this is ready for review

}];
XCTAssertNotNil(activeView);
}
// This assert proves the myInputPlugin.textInputView is not gc'd.
Copy link
Member

Choose a reason for hiding this comment

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

nit: s/gc'd/deallocated

@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 Mar 15, 2021
@fluttergithubbot fluttergithubbot merged commit 04b0451 into flutter:master Mar 15, 2021
zanderso pushed a commit to flutter/flutter that referenced this pull request Mar 16, 2021
* b2d02f7 Roll Fuchsia Linux SDK from GsRYVri0-... to aRqEDMjwC... (flutter/engine#24990)

* 3a1a3e6 Roll Skia from 7854da39b3c1 to 4fb13e026b6b (20 revisions) (flutter/engine#24993)

* e3a84f9 Fixed issue where the gpu disable syncswitch was being overridden after init. (flutter/engine#24958)

* aa83691 fix selectable text selections are not announced in voice over (flutter/engine#24933)

* 04b0451 fixes reference retaining issue in flutter text input plugin (flutter/engine#24768)

* 1ea7dc6 Set automatic simulator rotation in scenario test (flutter/engine#24985)

* 38977a5 Implement AXPlatformNodeBase::GetInstanceCountForTesting (flutter/engine#24999)

* a25b0de Roll Fuchsia Mac SDK from xOxFrRRO6... to pmsuWkRQA... (flutter/engine#24997)

* 3270c87 Roll Skia from 4fb13e026b6b to 1aa25c3217b6 (25 revisions) (flutter/engine#25001)

* 96d5104 [deferred components] Handle base module loading units (flutter/engine#24983)

* 6a3d8c7 Roll Skia from 1aa25c3217b6 to ead52dc068d5 (1 revision) (flutter/engine#25005)

* 0f52360 Hardware Keyboard: macOS (flutter/engine#23469)
hjfreyer pushed a commit to hjfreyer/engine that referenced this pull request Mar 22, 2021
chriscraws pushed a commit to chriscraws/engine that referenced this pull request Mar 23, 2021
duanqz pushed a commit to duanqz/engine that referenced this pull request Apr 16, 2021
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[IOS] When the obscureText parameter of CupertinoTextField is set to true, the focus is requested, then the focus is lost, and the application crashes

4 participants