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
164.87k stars 27.16k forks source link

iOS crash When Enable the graphics debugging switch #150928

Closed cj3479 closed 1 month ago

cj3479 commented 2 months ago

Steps to reproduce

I am using Flutter in a game app, and the game is based on the Unity engine. When opening Show Graphics HUD Develop tools (Setting->Developer->Show Graphics HUB)

Expected results

no crash

Actual results

crash

Code sample

Code sample ```dart [Paste your code here] ```

Screenshots or Video

Screenshots / Video demonstration [Upload media here]

Logs


Crash 1:

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Codes: 0x0000000000000001, 0x0000000000000000
VM Region Info: 0 is not in any region.  Bytes before following region: 4333486080
      REGION TYPE                 START - END      [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
Termination Reason: SIGNAL 11 Segmentation fault: 11
Terminating Process: exc handler [19097]

Triggered by Thread:  60

Thread 60 name:   Dispatch queue: com.Metal.CompletionQueueDispatch
Thread 60 Crashed:
0   libMTLHud.dylib                        0x2243fbbb0 Renderer::DrawText(char const*, int, unsigned int) + 340
1   libMTLHud.dylib                        0x2244004e4 Overlay::onPresent(id<CAMetalDrawable>) + 3368
2   libMTLHud.dylib                        0x2243fd724 CAMetalDrawable_presentAfterMinimumDuration(void (*)(), objc_object*, objc_selector*, double) + 76
3   libMTLHud.dylib                        0x2243fd914 invocation function for block in void replaceMethod<void, double>(objc_class*, objc_selector*, void (*)(void (*)(), objc_object*, objc_selector*, double)) + 68
4   Metal                                  0x19185cb60 __45-[_MTLCommandBuffer presentDrawable:options:]_block_invoke + 104
5   Metal                                  0x1918366f0 MTLDispatchListApply + 52
6   Metal                                  0x191836368 -[_MTLCommandBuffer didScheduleWithStartTime:endTime:error:] + 284
7   IOGPU                                  0x20dfa5100 IOGPUNotificationQueueDispatchAvailableCompletionNotifications + 128
8   IOGPU                                  0x20dfa5018 __IOGPUNotificationQueueSetDispatchQueue_block_invoke + 64
9   libdispatch.dylib                      0x199b7de94 _dispatch_client_callout4 + 20
10  libdispatch.dylib                      0x199b9a000 _dispatch_mach_msg_invoke + 468
11  libdispatch.dylib                      0x199b85284 _dispatch_lane_serial_drain + 368
12  libdispatch.dylib                      0x199b9ad50 _dispatch_mach_invoke + 444
13  libdispatch.dylib                      0x199b85284 _dispatch_lane_serial_drain + 368
14  libdispatch.dylib                      0x199b85f64 _dispatch_lane_invoke + 432
15  libdispatch.dylib                      0x199b85284 _dispatch_lane_serial_drain + 368
16  libdispatch.dylib                      0x199b85f30 _dispatch_lane_invoke + 380
17  libdispatch.dylib                      0x199b90cb4 _dispatch_root_queue_drain_deferred_wlh + 288
18  libdispatch.dylib                      0x199b90528 _dispatch_workloop_worker_thread + 404
19  libsystem_pthread.dylib                0x1eeb2f934 _pthread_wqthread + 288
20  libsystem_pthread.dylib                0x1eeb2c0cc start_wqthread + 8

</br></br>
Crash 2:

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Codes: 0x0000000000000001, 0x0000000000000000
VM Region Info: 0 is not in any region.  Bytes before following region: 4364435456
      REGION TYPE                 START - END      [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                   104240000-10e024000 [157.9M] r-x/r-x SM=COW  /var/containers/Bundle/Application/9A8B46E5-28F7-4742-940C-E8B6ECE7AF30/lolm.app/lolm
Triggered by Thread:  0

Kernel Triage:
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter

Thread 0 name:   Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libMTLHud.dylib                        0x232d68f4c Renderer::EndMergedDraw() + 48
1   libMTLHud.dylib                        0x232d685b8 Overlay::onPresent(id<CAMetalDrawable>) + 3579
2   libMTLHud.dylib                        0x232d65500 CAMetalDrawable_present(void (*)(), objc_object*, objc_selector*) + 67
3   libMTLHud.dylib                        0x232d65810 invocation function for block in void replaceMethod<void>(objc_class*, objc_selector*, void (*)(void (*)(), objc_object*, objc_selector*)) + 55
4   Flutter                                0x111f3f404 impeller::SurfaceMTL::Present() const + 5485572 (surface_mtl.mm:265)
5   Flutter                                0x111d739dc impeller::Renderer::Render(std::_fl::unique_ptr<impeller::Surface, std::_fl::default_delete<impeller::Surface>>, std::_fl::function<bool (impeller::RenderTarget&)> const&) const + 3602908 (renderer.cc:54)
6   Flutter                                0x111fcf8dc std::_fl::__function::__func<fml::internal::CopyableLambda<flutter::GPUSurfaceMetalImpeller::AcquireFrameFromCAMetalLayer(SkISize const&)::$_0>, std::_fl::allocator<fml::internal::CopyableLambda<flutter::GPUSurfaceMetalImpeller::AcquireFrameFromCAMetalLayer(SkISize const&)::$_0>>, bool (flutter::SurfaceFrame&, flutter::DlCanvas*)>::operator()(flutter::SurfaceFrame&, flutter::DlCanvas*&&) + 6076636 (function.h:359)
7   Flutter                                0x111ebbffc flutter::SurfaceFrame::Submit() + 4947964 (surface_frame.cc:51)
8   Flutter                                0x111a45b98 flutter::IOSExternalViewEmbedder::SubmitFlutterView(GrDirectContext*, std::_fl::shared_ptr<impeller::AiksContext> const&, std::_fl::unique_ptr<flutter::SurfaceFrame, std::_fl::default_delete<flutter::SurfaceFrame>>) + 269208 (ios_external_view_embedder.mm:82)
9   Flutter                                0x111df7d5c flutter::Rasterizer::DrawToSurfacesUnsafe(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>>>>) + 4144476 (rasterizer.cc:613)
10  Flutter                                0x111df82c4 std::_fl::__function::__func<flutter::Rasterizer::DrawToSurfaces(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>>>>)::$_1, std::_fl::allocator<flutter::Rasterizer::DrawToSurfaces(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>>>>)::$_1>, void ()>::operator()() + 4145860 (function.h:359)
11  Flutter                                0x111cef2c4 fml::SyncSwitch::Execute(fml::SyncSwitch::Handlers const&) const + 3060420 (sync_switch.cc:32)
12  Flutter                                0x111df7510 flutter::Rasterizer::DrawToSurfaces(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>>>>) + 4142352 (rasterizer.cc:544)
13  Flutter                                0x111df9114 std::_fl::__function::__func<flutter::Rasterizer::Draw(std::_fl::shared_ptr<flutter::Pipeline<flutter::FrameItem>> const&)::$_0, std::_fl::allocator<flutter::Rasterizer::Draw(std::_fl::shared_ptr<flutter::Pipeline<flutter::FrameItem>> const&)::$_0>, void (std::_fl::unique_ptr<flutter::FrameItem, std::_fl::default_delete<flutter::FrameItem>>)>::operator()(std::_fl::unique_ptr<flutter::FrameItem, std::_fl::default_delete<flutter::FrameItem>>&&) + 4149524 (function.h:359)
14  Flutter                                0x111df8960 flutter::Rasterizer::Draw(std::_fl::shared_ptr<flutter::Pipeline<flutter::FrameItem>> const&) + 4147552 (rasterizer.cc:246)
15  Flutter                                0x111e10e14 std::_fl::__function::__func<fml::internal::CopyableLambda<flutter::Shell::OnAnimatorDraw(std::_fl::shared_ptr<flutter::Pipeline<flutter::FrameItem>>)::$_0>, std::_fl::allocator<fml::internal::CopyableLambda<flutter::Shell::OnAnimatorDraw(std::_fl::shared_ptr<flutter::Pipeline<flutter::FrameItem>>)::$_0>>, void ()>::operator()() + 4247060 (function.h:359)
16  Flutter                                0x111ced930 fml::MessageLoopImpl::FlushTasks(fml::FlushType) + 3053872 (message_loop_impl.cc:128)
17  Flutter                                0x111cf10e4 fml::MessageLoopDarwin::OnTimerFire(__CFRunLoopTimer*, fml::MessageLoopDarwin*) + 3068132 (message_loop_darwin.mm:86)
18  CoreFoundation                         0x1a0674a2c __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 31
19  CoreFoundation                         0x1a06746d0 __CFRunLoopDoTimer + 1003
20  CoreFoundation                         0x1a067422c __CFRunLoopDoTimers + 287
21  CoreFoundation                         0x1a0610888 __CFRunLoopRun + 1855
22  CoreFoundation                         0x1a060fcd8 CFRunLoopRunSpecific + 607
23  GraphicsServices                       0x1e54c01a8 GSEventRunModal + 163
24  UIKitCore                              0x1a2c4890c -[UIApplication _run] + 887
25  UIKitCore                              0x1a2cfc9d0 UIApplicationMain + 339
26  lolm                                   0x104246460 0x104240000 + 25696
27  dyld                                   0x1c3cc1e4c start + 2239

Flutter Doctor output

[!] Flutter (Channel [user-branch], 3.19.6, on macOS 14.3 23D56 darwin-x64, locale zh-Hans-CN)
! Flutter version 3.19.6 on channel [user-branch] at /Users/chengjian/soft/flutter
Currently on an unknown channel. Run flutter channel to switch to an official channel.
If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
! Upstream repository unknown source is not a standard remote.
Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss this error.
• Framework revision https://github.com/flutter/flutter/commit/54e66469a933b60ddf175f858f82eaeb97e48c8d (2 个月前), 2024-04-17 13:08:03 -0700
• Engine revision c4cd48e186
• Dart version 3.3.4
• DevTools version 2.31.1
• If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades
cj3479 commented 2 months ago

@darshankawar can you help to handle the issue?

cj3479 commented 2 months ago

@jonahwilliams @gaaclarke can you help to handle the issue?

darshankawar commented 2 months ago

When opening Show Graphics HUD Develop tools (Setting->Developer->Show Graphics HUB)

@cj3479 Where are you doing this change ? Can you upgrade to latest master and re-run your scenario to check if the crash still persists or not ?

cj3479 commented 2 months ago

When opening Show Graphics HUD Develop tools (Setting->Developer->Show Graphics HUB)

@cj3479 Where are you doing this change ? Can you upgrade to latest master and re-run your scenario to check if the crash still persists or not ?

Yes I use latest master , It still crashes, I suspect that Flutter might be incompatible with Unity or Unreal when enable the graphics debugging switch

The Flutter app that do not embed into Unity or Unreal do not have this issue

gaaclarke commented 2 months ago
  1. Is this on device or simulator?
  2. How are you embedding flutter into unity?

It may be the case that you have improper synchronization between unity's renderer and flutter's renderer.

cj3479 commented 2 months ago
  1. Is this on device or simulator?
  2. How are you embedding flutter into unity?

It may be the case that you have improper synchronization between unity's renderer and flutter's renderer.

  1. It is device
  2. https://blog.codemagic.io/how-to-embed-an-android-unity-game-in-a-flutter-app/
huycozy commented 2 months ago

@cj3479 Similar to https://github.com/flutter/flutter/issues/150929#issuecomment-2224715020, it would be helpful if you could provide a complete sample code so that we can look into it easily. Thanks!

github-actions[bot] commented 1 month ago

Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now. If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones. Thanks for your contribution.

github-actions[bot] commented 4 weeks ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.