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

Conversation

@gaaclarke
Copy link
Member

Made the FlutterViewController's dealloc notification more generic and started turning off semantics when the view controller is remotely deleted.

Relevant issue: flutter/flutter#33173

generic and started turning off semantics when the view controller
is remotely deleted.
self.iosPlatformView->SetOwnerViewController(_viewController);
[self maybeSetupPlatformViewChannels];

self.flutterViewControllerWillDeallocObserver =
Copy link
Member

Choose a reason for hiding this comment

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

This is ok but consistency-wise seems a bit unnecessarily different. We already have _shell->GetPlatformView() all over the place in this file. Can't we just call _shell->GetPlatformView()->SetOwnerViewController(null) on notifyViewControllerDeallocated?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not doing that because that would be changing behavior outside the bounds of the problem I was fixing. I'm just moving this file over to the new mechanism I created so we don't have multiple ways to do the same thing. The only logical change I made here was calling _viewController.reset() in notifyViewControllerDeallocated . I didn't technically have to do that to solve the bug, but it will almost certainly cause a bug in a future to keep a weak pointer to a dealloced object. This will turn that future bug to a null pointer exception which will be easier for someone to fix than calling a method into random memory.

Copy link
Member

Choose a reason for hiding this comment

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

Discussed offline. Moving the direct plumbing to NSNotificationCenter is ok. If we're implicitly saying the precedent is also to promote moving other event plumbing to notification center.

@xster
Copy link
Member

xster commented Sep 13, 2019

This needs a test

@gaaclarke
Copy link
Member Author

This needs a test

Done. I attempted to add a test for PlatformViewIOS inside of the ios unit tests target, there isn't an existing unit test for this class. It isn't possible to test because PlatformViewIOS makes reference to symbols inside of Flutter.framework that aren't exported so any unit test target that references PlatformViewIOS.h will fail to link. We need to come up with a better solution for testing internal c++ classes.

Copy link
Member

@xster xster left a comment

Choose a reason for hiding this comment

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

LGTM.

Would be nice to add an integration test to scenario_apps too.

[self destroyContext];
}
_viewController.reset();
}
Copy link
Member

Choose a reason for hiding this comment

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

This should only happen once right? Should we get rid of the observer here too?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could. I wouldn't recommend it. It would make more sense inside of the observer's block but it isn't necessary there either since the semantics of the message are that the object is dying, it shouldn't be dying twice.


NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
[_flutterViewControllerWillDeallocObserver release];
Copy link
Member

Choose a reason for hiding this comment

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

I have a feeling if this happened before the view controller got dealloc'ed, it's probably a bug right? I don't think this can happen legitimately. Maybe we should print a message here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, that wouldn't be a bug. Releasing the observer detaches this object from the notification center for that message, so after that releasing the FlutterViewController will just not notify a FlutterEngine that he's being dealloc'd.


extern NSNotificationName const FlutterViewControllerWillDealloc;

/// OCMock can't be used for FlutterEngine sometimes because it retains arguments to invocations
Copy link
Member

Choose a reason for hiding this comment

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

I didn't understand this comment :D

Also, this is more a comment than a class doc right? Maybe //?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated the text to be more clear. I think /// is appropriate since its intention is to be a docstring.

if (ios_surface_ || !owner_controller) {
NotifyDestroyed();
ios_surface_.reset();
accessibility_bridge_.reset();
Copy link
Member

Choose a reason for hiding this comment

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

should we get rid of that observer here too?

Copy link
Member Author

Choose a reason for hiding this comment

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

We are getting rid of the observer a couple lines down, line 55. I don't believe there is any reason why it should be happening higher in the method.

self.iosPlatformView->SetOwnerViewController(_viewController);
[self maybeSetupPlatformViewChannels];

self.flutterViewControllerWillDeallocObserver =
Copy link
Member

Choose a reason for hiding this comment

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

Discussed offline. Moving the direct plumbing to NSNotificationCenter is ok. If we're implicitly saying the precedent is also to promote moving other event plumbing to notification center.

@gaaclarke
Copy link
Member Author

Would be nice to add an integration test to scenario_apps too.

I'll give this a stab on the bus.

@gaaclarke gaaclarke merged commit 5075172 into flutter:master Sep 14, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 16, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Sep 16, 2019
git@github.com:flutter/engine.git/compare/00c8941daeae...3f76f55

git log 00c8941..3f76f55 --no-merges --oneline
2019-09-15 iska.kaushik@gmail.com Revert "Roll src/third_party/dart a554c8be6b..d0052c1b31 (22 commits)" (flutter/engine#12290)
2019-09-14 30870216+gaaclarke@users.noreply.github.com FlutterViewController notify will dealloc (flutter/engine#12232)
2019-09-14 bkonyi@google.com Roll src/third_party/dart a554c8be6b..d0052c1b31 (22 commits)


If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC jimgraham@google.com on the revert to ensure that a human
is aware of the problem.

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
Inconnu08 pushed a commit to Inconnu08/flutter that referenced this pull request Sep 30, 2019
git@github.com:flutter/engine.git/compare/00c8941daeae...3f76f55

git log 00c8941..3f76f55 --no-merges --oneline
2019-09-15 iska.kaushik@gmail.com Revert "Roll src/third_party/dart a554c8be6b..d0052c1b31 (22 commits)" (flutter/engine#12290)
2019-09-14 30870216+gaaclarke@users.noreply.github.com FlutterViewController notify will dealloc (flutter/engine#12232)
2019-09-14 bkonyi@google.com Roll src/third_party/dart a554c8be6b..d0052c1b31 (22 commits)


If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC jimgraham@google.com on the revert to ensure that a human
is aware of the problem.

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants