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

Conversation

@knopp
Copy link
Member

@knopp knopp commented Aug 7, 2024

Fixes flutter/flutter#152990

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 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.

@knopp knopp requested a review from jmagman August 7, 2024 18:25
Comment on lines +287 to +290
CFTimeInterval start = CACurrentMediaTime();
while (weakLayer != nil && CACurrentMediaTime() - start < 1) {
// Deallocating the layer after removing is not synchronous.
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, YES);
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.01, YES);
Copy link
Member

@jmagman jmagman Aug 7, 2024

Choose a reason for hiding this comment

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

Would something like this work (I didn't try it):

@interface FlutterMetalLayerTest : XCTestCase
@property(weak) FlutterMetalLayer *weakLayer;
@end

- (void)testDealloc {
  @autoreleasepool {
...
    self.weakLayer = layer;
...
  }
  XCTestExpectation *weakNil = [self keyValueObservingExpectationForObject:self keyPath:@"weakLayer" expectedValue:nil];
  [self waitForExpectationsWithTimeout:1.0 handler:nil];

Copy link
Member

Choose a reason for hiding this comment

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

(I'm not sure about the KVO part, but it would be nice to let -waitForExpectations handle the runloop spinning.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jmagman, I don't think KVO will work since zeroing weak reference doesn't trigger KVO notifications. I tried this

- (void)testDealloc {
   __weak FlutterMetalLayer* weakLayer;
  @autoreleasepool {
    FlutterMetalLayer* layer = [self addMetalLayer];
    weakLayer = layer;
    TestCompositor* compositor = [[TestCompositor alloc] initWithLayer:layer];

    id<CAMetalDrawable> drawable = [layer nextDrawable];
    BAIL_IF_NO_DRAWABLE(drawable);
    [drawable present];
    [compositor commitTransaction];

    [self removeMetalLayer:layer];
  }
  NSPredicate* predicate =
      [NSPredicate predicateWithBlock:^(id evaluatedObject, NSDictionary* bindings) {
        return weakLayer == nil;
      }];
  [self expectationForPredicate:predicate evaluatedWithObject:self handler:nil];
  [self waitForExpectationsWithTimeout:1 handler:nil];
}

Unfortunately it didn't work either. I can confirm that weakLayer==nil is YES in the predicate and yet the expection fails. Maybe I'm holding it wrong but I'm not sure how.

Copy link
Member

Choose a reason for hiding this comment

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

since zeroing weak reference doesn't trigger KVO notifications

That's what I suspected, but I couldn't think other another way. Thanks for checking.

@jmagman jmagman added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 8, 2024
@auto-submit auto-submit bot merged commit 387f6f3 into flutter:main Aug 8, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 8, 2024
@knopp knopp deleted the metal_layer_test_flakiness branch August 8, 2024 17:48
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Aug 8, 2024
…153111)

flutter/engine@3978ddd...387f6f3

2024-08-08 [email protected] Fix FlutterMetalLayer testDealloc flakiness on iOS 18 (flutter/engine#54403)
2024-08-08 [email protected] [iOS] Bundle dSYM packages in Flutter.xcframework (flutter/engine#54414)
2024-08-08 [email protected] Roll Dart SDK from 0131aabd8631 to 067c7cfcbc8c (1 revision) (flutter/engine#54437)

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 [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@jmagman jmagman added the cp: stable cherry pick to the stable release candidate branch label Aug 8, 2024
@flutteractionsbot
Copy link

Failed to create CP due to merge conflicts.
You will need to create the PR manually. See the cherrypick wiki for more info.

@knopp
Copy link
Member Author

knopp commented Aug 8, 2024

The fix that this test is for has not been cherry-pick, so I don't think this test should be either. FlutterMetalLayer is not enabled by default in stable.

@jmagman
Copy link
Member

jmagman commented Aug 8, 2024

The fix that this test is for has not been cherry-pick, so I don't think this test should be either. FlutterMetalLayer is not enabled by default in stable.

Ha yeah, I remembered after the bot failed. Thanks!

DBowen33 pushed a commit to DBowen33/flutter that referenced this pull request Aug 16, 2024
…lutter#153111)

flutter/engine@3978ddd...387f6f3

2024-08-08 [email protected] Fix FlutterMetalLayer testDealloc flakiness on iOS 18 (flutter/engine#54403)
2024-08-08 [email protected] [iOS] Bundle dSYM packages in Flutter.xcframework (flutter/engine#54414)
2024-08-08 [email protected] Roll Dart SDK from 0131aabd8631 to 067c7cfcbc8c (1 revision) (flutter/engine#54437)

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 [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Buchimi pushed a commit to Buchimi/flutter that referenced this pull request Sep 2, 2024
…lutter#153111)

flutter/engine@3978ddd...387f6f3

2024-08-08 [email protected] Fix FlutterMetalLayer testDealloc flakiness on iOS 18 (flutter/engine#54403)
2024-08-08 [email protected] [iOS] Bundle dSYM packages in Flutter.xcframework (flutter/engine#54414)
2024-08-08 [email protected] Roll Dart SDK from 0131aabd8631 to 067c7cfcbc8c (1 revision) (flutter/engine#54437)

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 [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

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

Labels

autosubmit Merge PR when tree becomes green via auto submit App cp: stable cherry pick to the stable release candidate branch platform-ios

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-[FlutterMetalLayerTest testDealloc] is failing on Xcode 16 beta 5: ((weakLayer) == nil) failed

3 participants