flutter-unity-view-widget icon indicating copy to clipboard operation
flutter-unity-view-widget copied to clipboard

[iOS] App crashes on flutter 3.13

Open vatsaltanna-simformsolutions opened this issue 8 months ago • 11 comments

Describe the bug I have an app which is working fine on flutter version 3.7.11 and 3.10.6. But when I upgraded flutter sdk to 3.13.6 or 3.13.8, it just directly crashes.

To Reproduce Steps to reproduce the behavior:

  1. Take working a project on which was working on older version of flutter
  2. Run on flutter 3.13.*
  3. Observe error

Expected behavior App shouldn't crash.

Unity (please complete the following information):

  • OS: [iOS]
  • Version [2022.2.0]

Smartphone (please complete the following information):

  • Device: [iPhone 11]
  • OS: [iOS - 16.6.1]

Additional Context App boots up fine but when it reaches Unity initialisation than it crashes.

StackTrace This is the only stacktrace, I get.

[Subsystems] Discovering subsystems at path /var/containers/Bundle/Application/C906FCBE-D625-47D8-A738-6F69FDE5BB63/Runner.app/Frameworks/UnityFramework.framework/Data/UnitySubsystems
GfxDevice: creating device client; threaded=1; jobified=1
Initializing Metal device caps: Apple A13 GPU
Initialize engine version: 2022.1.24f1 (709dddfb713f)
* thread #10, name = 'io.flutter.1.raster', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x000000010e728e88 Flutter`impeller::ContentsFilterInput::GetCoverage(impeller::Entity const&) const + 4
Flutter`impeller::ContentsFilterInput::GetCoverage:
->  0x10e728e88 <+4>:  ldr    x9, [x0]
    0x10e728e8c <+8>:  ldr    x2, [x9, #0x18]
    0x10e728e90 <+12>: br     x2
Flutter`impeller::FilterContentsFilterInput::~FilterContentsFilterInput:
    0x10e728e94 <+0>:  stp    x20, x19, [sp, #-0x20]!
Target 0: (Runner) stopped.
Lost connection to device.

The new Flutter versions changed the rendering engine from Skia to Impeller on iOS. It introduced some bugs, but they seem to quickly fix all those that pop up.

Can you try running your app with Impeller disabled on the newest version 3.13.x? That should clarify if it is related to the Impeller changes.

timbotimbo avatar Nov 05 '23 17:11 timbotimbo

@timbotimbo Thanks for the reply. Flutter's default rendering engine for iOS has changed to Impeller since Flutter version 3.7, and while running it in version 3.7 or 3.10, it wouldn't crash the app. This is happening only for version 3.13.

I just tried disabling Impeller in the Runner Info.plist and it still crashes.

Velek avatar Nov 07 '23 02:11 Velek

I can now confirm new crashes with 3.13, but i'm not sure if it is the same one.

Setup:

  • Mac OS Sonoma 14.1
  • iPad on iPad OS 16
  • Unity 2021.3.21f
  • Xcode 15.0.1
  • Flutter (3.13.3 and 3.13.9)
  • Existing project using flutter_unity_widget

Launching the app from Xcode instantly crashes the app, while it used to work.


Troubleshooting

I got it working for now in 2 steps, but I need to look into it further.

  • I changed the minimum iOS deployment target to 12 (both for the Runner and all pods). The app doesn't crash on launch anymore.

(make sure to clean the build and run pod install again)

#podfile instructions for setting all pod deployment targets
platform :ios, '12' #at the top

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
    end
  end
end

With flutter 3.13.3 it now randomly crashes on UI interactions, with 3.13.9 it seems more stable.

  • I disabled Impeller using info.plist
  <key>FLTEnableImpeller</key>
  <false />

Now I don't see any crashes.


I still need to figure out more, but this might work for others too.

timbotimbo avatar Nov 07 '23 17:11 timbotimbo

It still crashes on launch for me. I had to integrate your change with my Podfile because it's already being modified so I can use XCode 15.

post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) target.build_configurations.each do |config| config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0' xcconfig_path = config.base_configuration_reference.real_path xcconfig = File.read(xcconfig_path) xcconfig_mod = xcconfig.gsub(/DT_TOOLCHAIN_DIR/, "TOOLCHAIN_DIR") File.open(xcconfig_path, "w") { |file| file << xcconfig_mod } end end end

Velek avatar Nov 08 '23 03:11 Velek

@Velek Can you give more context?

  • Do you crash on launch of the app or launch of the unitywidget?
  • Is this only on a custom project or also with the example?
  • Exact versions for Flutter, Unity, etc.
  • Did you make a debug or release export in Unity?
  • Any custom logic in the onCreate callback of the unitywidget.

The DT_Toolchain fix for Xcode 15 in your podfile shouldn't be needed if you update cocoapods to the latest version, they fixed that already. Can't hurt to update it, you never know if it can somehow cause another issue.

timbotimbo avatar Nov 08 '23 08:11 timbotimbo

Update: I have tried to run a project with Flutter 3.16.1 and it now works fine for iOS 16 but crashes for iOS 17 .

@vatsaltanna-simformsolutions @timbotimbo the error you see from the raster crash is not the cause of the crash. I have enabled and used Impeller on iOS devices before it was made default for flutter. The easiest way to explain it is there's more to it than meets the eye. What you are is a stacktrace of the effect and not what caused the error. I am trying to replicate it and see if I can fix it.

juicycleff avatar Jan 15 '24 04:01 juicycleff

Hi @juicycleff, I hope you are doing good. Did you get a chance to check on this issue?

@vatsaltanna-simformsolutions Can you share more info besides Flutter version? I can't reproduce this error right now and more details might help.

  • Which Unity version, Xcode version and FUW plugin version
  • Do you get the same crash with the example unity project?
  • Do you use any extra packages or plugins in Unity?
  • On which devices does the crash happen ?(e.g iphone 14, ios 17)

Just for context, my latest app update was built with Flutter 3.13.9, Unity 2022.3.21 and Xcode 15.3. It targets ios >= 12 and has impeller disabled. (Impeller is disabled simply because I never updated that yet). I have yet to see any such crashes.

The only reason i'm still on 3.13 is because of some unrelated android issues.

timbotimbo avatar Mar 27 '24 16:03 timbotimbo

  • Unity version: 2022.1.24f1 (silicon), Xcode version: 14.0.0 (14A309), FUW plugin is a modified version of the publicly available one. It was modified by rex.
  • Haven't tried on the sample project.
  • Yes. We have quite a few extra packages.
  • Iphone 11 (IOS 16.6.1)

We are facing crashing with impeller enabled and we need to have it to be enabled. So can you please try building with impeller enabled?