juicycleff / flutter-unity-view-widget

Embeddable unity game engine view for Flutter. Advance demo here https://github.com/juicycleff/flutter-unity-arkit-demo
BSD 3-Clause "New" or "Revised" License
2.09k stars 505 forks source link

[iOS] App crashes on flutter 3.13 #890

Open vatsaltanna-simformsolutions opened 8 months ago

vatsaltanna-simformsolutions commented 8 months ago

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):

Smartphone (please complete the following information):

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.
timbotimbo commented 8 months ago

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.

vatsaltanna-simformsolutions commented 8 months ago

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

Velek commented 8 months ago

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

timbotimbo commented 8 months ago

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

Setup:

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.

(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 still need to figure out more, but this might work for others too.

Velek commented 8 months ago

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

timbotimbo commented 8 months ago

@Velek Can you give more context?

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.

vatsaltanna-simformsolutions commented 7 months ago

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 .

juicycleff commented 5 months ago

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

vatsaltanna-simformsolutions commented 3 months ago

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

timbotimbo commented 3 months ago

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

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.

vatsaltanna-simformsolutions commented 3 months ago

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?