Repository: flutter
Issue: [iOS] GrMtlGpu::submitCommandBuffer(GrMtlGpu::SyncQueue)
Labels: c: crash,engine,a: production,P3,needs repro info,team-engine,triaged-engine

### Steps to reproduce

Unfortunately not able to reproduce locally.

### Expected results

Not crash

### Actual results

App is crashing.

### Code sample

<details open><summary>Code sample</summary>

```dart
[Paste your code here]
```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

![Screenshot 2024-06-07 at 3 02 15 PM](https://github.com/flutter/flutter/assets/74494959/4695148d-9ed1-4f7e-bdf3-1fd3acfbef1c)
![Screenshot 2024-06-07 at 3 02 09 PM](https://github.com/flutter/flutter/assets/74494959/d86cab34-6822-4ba9-bd4f-6b5d12a57c20)

</details>


### Logs

<details open><summary>Logs</summary>

```console
Crashed: SingleEngine-deeplinkMain.5.raster
0  libobjc.A.dylib                0x1d530 objc_msgSend + 16
1  libsystem_trace.dylib          0x7ff8 _os_log_fmt_flatten_data + 136
2  libsystem_trace.dylib          0xe7c8 _os_log_impl_flatten_and_send + 1632
3  libsystem_trace.dylib          0x10d7c _os_log_with_args_impl + 396
4  CoreFoundation                 0x109780 _CFLog_os_log_shim + 68
5  CoreFoundation                 0x1096bc _CFLogvEx3 + 128
6  Foundation                     0x11a438 _NSLogv + 124
7  Foundation                     0x11a46c NSLog + 32
8  Flutter                        0x272ff8 GrMtlGpu::submitCommandBuffer(GrMtlGpu::SyncQueue) + 225 (GrMtlCommandBuffer.mm:225)
9  Flutter                        0x1caa08 GrGpu::submitToGpu(GrSyncCpu) + 760 (GrGpu.cpp:760)
10 Flutter                        0x5c8bf0 std::_fl::__function::__func<flutter::GPUSurfaceMetalSkia::AcquireFrameFromCAMetalLayer(SkISize const&)::$_0, std::_fl::allocator<flutter::GPUSurfaceMetalSkia::AcquireFrameFromCAMetalLayer(SkISize const&)::$_0>, bool (flutter::SurfaceFrame&, flutter::DlCanvas*)>::operator()(flutter::SurfaceFrame&, flutter::DlCanvas*&&) + 167 (gpu_surface_metal_skia.mm:167)
11 Flutter                        0x4b767c flutter::SurfaceFrame::Submit() + 51 (surface_frame.cc:51)
12 Flutter                        0x3f33b0 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>>>>) + 752 (rasterizer.cc:752)
13 Flutter                        0x3f389c 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()() + 552 (rasterizer.cc:552)
14 Flutter                        0x2ea89c fml::SyncSwitch::Execute(fml::SyncSwitch::Handlers const&) const + 29 (shared_mutex.h:29)
15 Flutter                        0x3f2ae8 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>>>>) + 470 (function.h:470)
16 Flutter                        0x3f46ec 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>>&&) + 423 (vector:423)
17 Flutter                        0x3f3f38 flutter::Rasterizer::Draw(std::_fl::shared_ptr<flutter::Pipeline<flutter::FrameItem>> const&) + 259 (unique_ptr.h:259)
18 Flutter                        0x40c3ec 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()() + 1260 (shell.cc:1260)
19 Flutter                        0x2e8f08 fml::MessageLoopImpl::FlushTasks(fml::FlushType) + 128 (message_loop_impl.cc:128)
20 Flutter                        0x2ec6bc fml::MessageLoopDarwin::OnTimerFire(__CFRunLoopTimer*, fml::MessageLoopDarwin*) + 86 (message_loop_darwin.mm:86)
21 CoreFoundation                 0xab554 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 28
22 CoreFoundation                 0xab284 __CFRunLoopDoTimer + 864
23 CoreFoundation                 0xaaab8 __CFRunLoopDoTimers + 248
24 CoreFoundation                 0xa5a08 __CFRunLoopRun + 1844
25 CoreFoundation                 0xa4fb4 CFRunLoopRunSpecific + 436
26 Flutter                        0x2ec7a8 fml::MessageLoopDarwin::Run() + 52 (message_loop_darwin.mm:52)
27 Flutter                        0x2ebe20 void* std::_fl::__thread_proxy[abi:v15000]<std::_fl::tuple<std::_fl::unique_ptr<std::_fl::__thread_struct, std::_fl::default_delete<std::_fl::__thread_struct>>, fml::Thread::Thread(std::_fl::function<void (fml::Thread::ThreadConfig const&)> const&, fml::Thread::ThreadConfig const&)::$_0>>(void*) + 94 (message_loop_impl.cc:94)
28 libsystem_pthread.dylib        0xb2c0 <redacted> + 128
29 libsystem_pthread.dylib        0xb220 _pthread_start + 44
30 libsystem_pthread.dylib        0xecdc thread_start + 4
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.19.4, on macOS 14.4.1 23E224 darwin-arm64, locale en-AE)
    • Flutter version 3.19.4 on channel stable at /Users/brunoreginato/fvm/versions/3.19.4
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 68bfaea224 (3 months ago), 2024-03-20 15:36:31 -0700
    • Engine revision a5c24f538d
    • Dart version 3.3.2
    • DevTools version 2.31.1

[!] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/brunoreginato/Library/Android/sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C500b
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • 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
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.2.3)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 75.1.4
    • Dart plugin version 232.10072.19

[✓] 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 Xs (mobile) • 121672A1-B308-4EAC-8031-0CF1665476C8 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-2 (simulator)
    • macOS (desktop)    • macos                                • darwin-arm64   • macOS 14.4.1 23E224 darwin-arm64
    • Chrome (web)       • chrome                               • web-javascript • Google Chrome 125.0.6422.142
    ! Error: Browsing on the local area network for Ahmed Henawey’s iPhone. Ensure the device is unlocked and attached with a cable or associated with the
      same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.
```

</details>