flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.35k stars 27.54k forks source link

Multiple sub-page of a navigation controller have a FlutterNativeView with the same registration type, e.g. B->C,C page pops back to B, crash. #149400

Open zhoujun951236 opened 5 months ago

zhoujun951236 commented 5 months ago

Steps to reproduce

When I use multi-engine mode A navigation stack with multiple sub-surfaces all have a FlutterNativeView with the same registration type, e.g. B->C, C page pops back to B, crash. When I use single engine mode then everything is fine

Expected results

no crash

Actual results

crash

Thread 1: signal SIGABRT image

Code sample

Code sample ```swift if !singleEngine {// wait “https://github.com/flutter/flutter/issues/127168” let groupOptions = FlutterEngineGroupOptions() groupOptions.entrypoint = entrypoint groupOptions.initialRoute = initRoute groupOptions.entrypointArgs = [FlutterEngineBinding.deviceInfo()] groupOptions.libraryURI = nil engine = FlutterContainerManager.shared.group.makeEngine(with: groupOptions) }else{ engine.run(withEntrypoint: entrypoint, libraryURI: nil, initialRoute: initRoute, entrypointArgs: [FlutterEngineBinding.deviceInfo()]) } ```

Screenshots or Video

Screenshots / Video demonstration [Upload media here]

Logs

Logs ```console [Paste your logs here] ```

Flutter Doctor output

Doctor output ```console flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.22.1, on macOS 14.4.1 23E224 darwin-arm64, locale zh-Hans-CN) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4) [✓] Xcode - develop for iOS and macOS (Xcode 15.4) [✓] Chrome - develop for the web [✓] Android Studio (version 2023.2) [✓] VS Code (version 1.89.1) [✓] Connected device (4 available) ```

I found version:3.16.5,3.19.5 also have this crash

zhoujun951236 commented 5 months ago

It is also mentioned here

zhoujun951236 commented 5 months ago

127168

zhoujun951236 commented 5 months ago

public required init(initRoute: String) { let singleEngine = BTOnlineConfig.MobileSwitch.boolValue(function: "FlutterSetting", forKey: "enableSingleEngine") if !singleEngine {// wait https://github.com/flutter/flutter/issues/127168 let groupOptions = FlutterEngineGroupOptions() groupOptions.entrypoint = entrypoint groupOptions.initialRoute = initRoute groupOptions.entrypointArgs = [FlutterEngineBinding.deviceInfo()] groupOptions.libraryURI = nil engine = FlutterContainerManager.shared.group.makeEngine(with: groupOptions) }else{ engine.run(withEntrypoint: entrypoint, libraryURI: nil, initialRoute: initRoute, entrypointArgs: [FlutterEngineBinding.deviceInfo()]) }

    super.init()
    GeneratedPluginRegistrant.register(with: engine)

    channel = FlutterMethodChannel(name: channelName,
                                   binaryMessenger: engine.binaryMessenger)

    let factory = FlutterNativeViewFactory(messenger: engine.binaryMessenger)
    engine.registrar(forPlugin: "plugin_name1")!.register(factory, withId: "platform-view-type1")
}

This is how I registered on the ios platform

dart: if (Platform.isIOS) { platformView = UiKitView( viewType: 'platform-view-type1', layoutDirection: TextDirection.ltr, creationParams: creationParams, creationParamsCodec: const JSONMessageCodec(), gestureRecognizers: Set()..add(Factory(() => VerticalDragGestureRecognizer())), onPlatformViewCreated: (index) { widget.onCreated?.call(); _changePlatformViewVisible(); }, );

huycozy commented 5 months ago

Hi @zhoujun951236 Do you use the complete sample project I shared at https://github.com/flutter/flutter/issues/127168#issuecomment-1554530173?

I just retried running it but couldn't reproduce the crash, it works as expected on the latest Flutter 3.22.1.

Demo https://github.com/flutter/flutter/assets/104349824/8b737186-3626-4fd2-b61a-524ce939d573

If you have modified the sample code, please share the updated one here (a GitHub repo or compressed sample project). Thanks!

zhoujun951236 commented 5 months ago

I'm sorry maybe I'm not describing it accurately, there's a missing link in your video, which is that the PlatformViewPage needs to push another PlatformViewPage and then pop back to the previous page

zhoujun951236 commented 5 months ago

sorry,I realized that there might be a problem with my flutter code and I closed it. #127168 Already fixed the problem with multi-tier pages Platformview

huycozy commented 5 months ago

@zhoujun951236 Do you still experience this issue?

zhoujun951236 commented 5 months ago

I stabilized a reproduction of this crash and also provided a demo

zhoujun951236 commented 5 months ago

demo

zhoujun951236 commented 5 months ago

https://github.com/flutter/flutter/assets/6309671/16124568-2001-4382-8fac-c2e687c9bff2

Steps are like this, the first step first click on the model_2 button, then click on the “flutter vc inner jumpto page”, then click on the "flutter vc inner pop", the interface pop and then click on this "flutter vc inner pop"

zhoujun951236 commented 5 months ago

screenshot

zhoujun951236 commented 5 months ago

My iphone is iPhone 11 with system version 15.1

huycozy commented 5 months ago

Thanks, I can reproduce the crash on my end using your given sample code above: https://github.com/zhoujun951236/testFlutterPlatformView (checked on iPhone 15 Pro iOS 17.4 emulator).

Crash output log: https://pastebin.com/biRjprir

Demo steps https://github.com/flutter/flutter/assets/104349824/3b231bb2-d875-4b75-9fa4-cafcc5cb0e88
flutter doctor -v ```bash [✓] Flutter (Channel stable, 3.22.2, on macOS 14.1 23B74 darwin-x64, locale en-VN) • Flutter version 3.22.2 on channel stable at /Users/huynq/Documents/GitHub/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 761747bfc5 (31 hours ago), 2024-06-05 22:15:13 +0200 • Engine revision edd8546116 • Dart version 3.4.3 • DevTools version 2.34.3 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/huynq/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • ANDROID_HOME = /Users/huynq/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.3) • Xcode at /Applications/Xcode15.3.app/Contents/Developer • Build 15E204a • CocoaPods version 1.15.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2023.3) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • android-studio-dir = /Applications/Android Studio.app/ • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160) [✓] VS Code (version 1.89.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.90.0 [✓] Connected device (3 available) • iPhone (mobile) • d9a94afe2b649fef56ba0bfeb052f0f2a7dae95e • ios • iOS 15.8 19H370 • macOS (desktop) • macos • darwin-x64 • macOS 14.1 23B74 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 125.0.6422.142 [✓] Network resources • All expected network resources are available. • No issues found! ```
jmagman commented 5 months ago
3   Flutter                                0x10accd1ff fml::KillProcess() + 9
4   Flutter                                0x10accd1f6 fml::LogMessage::~LogMessage() + 378
5   Flutter                                0x10acd0c1e fml::SharedThreadMerger::DecrementLease(void*) + 272
6   Flutter                                0x10acd0711 fml::RasterThreadMerger::DecrementLease() + 95
7   Flutter                                0x10ae17035 flutter::Rasterizer::DoDraw(std::_fl::unique_ptr<flutter::FrameTimingsRecorder, std::_fl::default_delete<flutter::FrameTimingsRecorder>>, std::_fl::vector<std::_fl::unique_ptr<flutter::LayerTreeTask, std::_fl::default_delete<flutter::LayerTreeTask>>, std::_fl::allocator<std::_fl::unique_ptr<flutter::LayerTreeTask, std::_fl::default_delete<flutter::LayerTreeTask>>>>) + 551

https://github.com/flutter/engine/blob/b3dc3ec2bd2856775aeb94782685203522007357/fml/shared_thread_merger.cc#L59-L62

cc @eggfly who worked on this thread merging code a few years ago.

vashworth commented 5 months ago

cc @hellohuanlin

zhoujun951236 commented 2 months ago

I found that adding canpop prevents the crash