Skip to content

macos embedder crashes when pumping the event loop with running engine #115599

@gaaclarke

Description

@gaaclarke

When trying to write a test I found that pumping the event loop with a running engine creates a crash. I believe this is indicative of a deeper bug in the embedder. Possibly a codepath is taken that is assuming there is a view controller for an engine that isn't setup in the test?

simple test

TEST_F(FlutterEngineTest, ResponseFromBackgroundThread) {
  FlutterEngine* engine = GetFlutterEngine();
  EXPECT_TRUE([engine runWithEntrypoint:@"main"]);

  for (int  i =0; i < 10; ++i) {
    [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
  }
}

backlog

Process 89471 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
    frame #0: 0x00007ff81174b72a libobjc.A.dylib`objc_loadWeakRetained + 170
libobjc.A.dylib`objc_loadWeakRetained:
->  0x7ff81174b72a <+170>: movq   0x20(%rbx), %rcx
    0x7ff81174b72e <+174>: testb  $0x4, %cl
    0x7ff81174b731 <+177>: jne    0x7ff81174b7e7            ; <+359>
    0x7ff81174b737 <+183>: movq   (%rbx), %rax
Target 0: (flutter_desktop_darwin_unittests) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
  * frame #0: 0x00007ff81174b72a libobjc.A.dylib`objc_loadWeakRetained + 170
    frame #1: 0x00000001001aac55 flutter_desktop_darwin_unittests`flutter::FlutterTextPlatformNode::GetFrame(this=0x00007ff7bfefe490) at FlutterTextInputSemanticsObject.mm:173:8
    frame #2: 0x00000001001aabd9 flutter_desktop_darwin_unittests`-[FlutterTextField frame](self=0x000000010bf30820, _cmd="frame") at FlutterTextInputSemanticsObject.mm:94:17
    frame #3: 0x00007ff81442a38c AppKit`-[NSView _alignmentFrame] + 43
    frame #4: 0x00007ff814454293 AppKit`-[NSView(NSConstraintBasedLayout) _calculateSubviewAlignmentFrame:superviewAlignmentBounds:forAutoresizingMask:] + 178
    frame #5: 0x00007ff814454147 AppKit`-[NSView(NSConstraintBasedLayout) _constraintsEquivalentToAutoresizingMask] + 119
    frame #6: 0x00007ff81445408a AppKit`-[NSView(NSConstraintBasedLayout) _updateAutoresizingConstraints] + 119
    frame #7: 0x00007ff814453fb1 AppKit`-[NSView updateConstraints] + 102
    frame #8: 0x00007ff814455bd4 AppKit`-[NSTextField updateConstraints] + 633
    frame #9: 0x00007ff814453ed3 AppKit`_NSViewUpdateConstraints + 95
    frame #10: 0x00007ff814453bf5 AppKit`-[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 849
    frame #11: 0x00007ff814453a4e AppKit`-[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 426
    frame #12: 0x00007ff814453a4e AppKit`-[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 426
    frame #13: 0x00007ff8144537b1 AppKit`__45-[NSView updateConstraintsForSubtreeIfNeeded]_block_invoke + 48
    frame #14: 0x00007ff814453582 AppKit`-[NSView updateConstraintsForSubtreeIfNeeded] + 229
    frame #15: 0x00007ff81447c3de AppKit`__62-[NSWindow(NSConstraintBasedLayout) updateConstraintsIfNeeded]_block_invoke + 134
    frame #16: 0x00007ff81447c302 AppKit`-[NSWindow(NSConstraintBasedLayout) updateConstraintsIfNeeded] + 253
    frame #17: 0x00007ff81447c145 AppKit`__NSWindowGetDisplayCycleObserverForUpdateConstraints_block_invoke + 430
    frame #18: 0x00007ff81447bf57 AppKit`NSDisplayCycleObserverInvoke + 155
    frame #19: 0x00007ff81447bae4 AppKit`NSDisplayCycleFlush + 921
    frame #20: 0x00007ff818a29fbe QuartzCore`CA::Transaction::run_commit_handlers(CATransactionPhase) + 98
    frame #21: 0x00007ff818a28cdc QuartzCore`CA::Transaction::commit() + 376
    frame #22: 0x00007ff81451d1d1 AppKit`__62+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayLink]_block_invoke + 285
    frame #23: 0x00007ff814c64f5c AppKit`___NSRunLoopObserverCreateWithHandler_block_invoke + 41
    frame #24: 0x00007ff811978520 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    frame #25: 0x00007ff8119783b2 CoreFoundation`__CFRunLoopDoObservers + 543
    frame #26: 0x00007ff811977844 CoreFoundation`__CFRunLoopRun + 840
    frame #27: 0x00007ff811976e3c CoreFoundation`CFRunLoopRunSpecific + 562
    frame #28: 0x00007ff8127d4d4a Foundation`-[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 216
    frame #29: 0x00007ff81285ac21 Foundation`-[NSRunLoop(NSRunLoop) runUntilDate:] + 103
    frame #30: 0x0000000100076f98 flutter_desktop_darwin_unittests`flutter::testing::FlutterEngineTest_ResponseFromBackgroundThread_Test::TestBody(this=0x00006000005857c0) at FlutterEngineTest.mm:664:5

Metadata

Metadata

Assignees

No one assigned

    Labels

    engineflutter/engine related. See also e: labels.platform-macBuilding on or for macOS specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions