Repository: flutter
Issue: iOS crash - flutter::Rasterizer::DrawToSurface - std::__1::mutex::lock()
Labels: c: crash,platform-ios,engine,a: production,P2,team-ios,triaged-ios

<!-- Thank you for using Flutter!

     If you are looking for support, please check out our documentation
     or consider asking a question on Stack Overflow:
      * https://flutter.dev/
      * https://api.flutter.dev/
      * https://stackoverflow.com/questions/tagged/flutter?sort=frequent

     If you have found a bug or if our documentation doesn't have an answer
     to what you're looking for, then fill out the template below. Please read
     our guide to filing a bug first: https://flutter.dev/docs/resources/bug-reports
-->

## Steps to Reproduce

No. The crash log is from FirebaseCrashlytic.

device info: 
1. iPad (9th generation)  iPadOS 16.1.1
2. iPad (8th generation) iPadOS 15.6.1
3. iPad (7th generation) iPadOS 15.6.1
4. iPad Pro (12.9-inch, 5th generation) iPadOS 15.7.0


**Expected results:** 
No crash

**Actual results:**
crash


<!--
      Please create a minimal reproducible sample that shows the problem
      and attach it below between the lines with the backticks.

      To create it you can use `flutter create bug` command and update the `main.dart` file.

      Alternatively, you can use https://dartpad.dev/
      which is capable of creating and running small Flutter apps.

      Without this we will unlikely be able to progress on the issue, and because of that
      we regretfully will have to close it.
-->

</details>

<details>
  <summary>Logs</summary>

```
Crashed: io.flutter.1.ui
0  FirebaseCrashlytics            0x222d0 FIRCLSProcessRecordAllThreads + 393 (FIRCLSProcess.c:393)
1  FirebaseCrashlytics            0x226b0 FIRCLSProcessRecordAllThreads + 424 (FIRCLSProcess.c:424)
2  FirebaseCrashlytics            0x18608 FIRCLSHandler + 34 (FIRCLSHandler.m:34)
3  FirebaseCrashlytics            0x12828 __FIRCLSExceptionRecord_block_invoke + 232 (FIRCLSException.mm:232)
4  libdispatch.dylib              0x3a30 _dispatch_client_callout + 20
5  libdispatch.dylib              0x12c90 _dispatch_lane_barrier_sync_invoke_and_complete + 56
6  FirebaseCrashlytics            0x11608 FIRCLSExceptionRecord + 234 (FIRCLSException.mm:234)
7  FirebaseCrashlytics            0x112c0 FIRCLSTerminateHandler() + 404 (FIRCLSException.mm:404)
8  libc++abi.dylib                0x10f18 std::__terminate(void (*)()) + 20
9  libc++abi.dylib                0x13ebc __cxa_rethrow + 148
10 libobjc.A.dylib                0x186c0 objc_exception_rethrow + 44
11 CoreFoundation                 0x1ecb4 CFRunLoopRunSpecific + 836
12 Flutter                        0x308a18 fml::MessageLoopDarwin::Run() + 4668607000
13 Flutter                        0x3083fc void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, fml::Thread::Thread(std::__1::function<void (fml::Thread::ThreadConfig const&)> const&, fml::Thread::ThreadConfig const&)::$_0> >(void*) + 4668605436
14 libsystem_pthread.dylib        0x19ac _pthread_start + 148
15 libsystem_pthread.dylib        0xe68 thread_start + 8
```

For 'com.apple.main-thread'
```
com.apple.main-thread
0  libsystem_kernel.dylib         0xb48 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x13008 mach_msg2_internal + 80
2  libsystem_kernel.dylib         0x13248 mach_msg_overwrite + 388
3  libsystem_kernel.dylib         0x108c mach_msg + 24
4  CoreFoundation                 0x7aaf0 __CFRunLoopServiceMachPort + 160
5  CoreFoundation                 0x7bd34 __CFRunLoopRun + 1232
6  CoreFoundation                 0x80ed4 CFRunLoopRunSpecific + 612
7  GraphicsServices               0x1368 GSEventRunModal + 164
8  UIKitCore                      0x3a23d0 -[UIApplication _run] + 888
9  UIKitCore                      0x3a2034 UIApplicationMain + 340
10 Runner                         0xa1dc main + 8 (AppDelegate.swift:8)
11 ???                            0x1dab1c960 (缺少)

```

For 'io.flutter.1.raster'
```
io.flutter.1.raster
0  libsystem_kernel.dylib         0x1b48 __psynch_mutexwait + 8
1  libsystem_pthread.dylib        0x2150 _pthread_mutex_firstfit_lock_wait + 84
2  libsystem_pthread.dylib        0x9310 _pthread_mutex_firstfit_lock_slow + 248
3  libc++.1.dylib                 0xe9f0 std::__1::mutex::lock() + 16
4  Flutter                        0x307008 fml::SyncSwitch::Execute(fml::SyncSwitch::Handlers const&) const + 4672417800
5  Flutter                        0x3e1098 flutter::Rasterizer::DrawToSurface(flutter::FrameTimingsRecorder&, flutter::LayerTree&) + 4673310872
6  Flutter                        0x3e2c24 std::__1::__function::__func<flutter::Rasterizer::Draw(std::__1::unique_ptr<flutter::FrameTimingsRecorder, std::__1::default_delete<flutter::FrameTimingsRecorder> >, std::__1::shared_ptr<flutter::Pipeline<flutter::LayerTree> >, std::__1::function<bool (flutter::LayerTree&)>)::$_2, std::__1::allocator<flutter::Rasterizer::Draw(std::__1::unique_ptr<flutter::FrameTimingsRecorder, std::__1::default_delete<flutter::FrameTimingsRecorder> >, std::__1::shared_ptr<flutter::Pipeline<flutter::LayerTree> >, std::__1::function<bool (flutter::LayerTree&)>)::$_2>, void (std::__1::unique_ptr<flutter::LayerTree, std::__1::default_delete<flutter::LayerTree> >)>::operator()(std::__1::unique_ptr<flutter::LayerTree, std::__1::default_delete<flutter::LayerTree> >&&) + 4673317924
7  Flutter                        0x3e1ec0 flutter::Rasterizer::Draw(std::__1::unique_ptr<flutter::FrameTimingsRecorder, std::__1::default_delete<flutter::FrameTimingsRecorder> >, std::__1::shared_ptr<flutter::Pipeline<flutter::LayerTree> >, std::__1::function<bool (flutter::LayerTree&)>) + 4673314496
8  Flutter                        0x3ebf88 std::__1::__function::__func<fml::internal::CopyableLambda<flutter::Shell::OnAnimatorDraw(std::__1::shared_ptr<flutter::Pipeline<flutter::LayerTree> >, std::__1::unique_ptr<flutter::FrameTimingsRecorder, std::__1::default_delete<flutter::FrameTimingsRecorder> >)::$_13>, std::__1::allocator<fml::internal::CopyableLambda<flutter::Shell::OnAnimatorDraw(std::__1::shared_ptr<flutter::Pipeline<flutter::LayerTree> >, std::__1::unique_ptr<flutter::FrameTimingsRecorder, std::__1::default_delete<flutter::FrameTimingsRecorder> >)::$_13> >, void ()>::operator()() + 4673355656
9  Flutter                        0x30584c fml::MessageLoopImpl::FlushTasks(fml::FlushType) + 4672411724
10 Flutter                        0x308b48 fml::MessageLoopDarwin::OnTimerFire(__CFRunLoopTimer*, fml::MessageLoopDarwin*) + 4672424776
11 CoreFoundation                 0xce35c __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 32
12 CoreFoundation                 0x8a9d8 __CFRunLoopDoTimer + 940
13 CoreFoundation                 0x2e598 __CFRunLoopDoTimers + 288
14 CoreFoundation                 0x7bfcc __CFRunLoopRun + 1896
15 CoreFoundation                 0x80ed4 CFRunLoopRunSpecific + 612
16 Flutter                        0x308a18 fml::MessageLoopDarwin::Run() + 4672424472
17 Flutter                        0x3083fc void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, fml::Thread::Thread(std::__1::function<void (fml::Thread::ThreadConfig const&)> const&, fml::Thread::ThreadConfig const&)::$_0> >(void*) + 4672422908
18 libsystem_pthread.dylib        0x16cc _pthread_start + 148
19 libsystem_pthread.dylib        0xba4 thread_start + 8
```

For 'io.flutter.1.io'
```
io.flutter.1.io
0  Flutter                        0x6e9b4 SkData::PrivateNewWithCopy(void const*, unsigned long) + 4669696436
1  Flutter                        0xdef28 MakeRasterCopyPriv(SkPixmap const&, unsigned int) + 4670156584
2  Flutter                        0x200294 SkImage::MakeCrossContextFromPixmap(GrDirectContext*, SkPixmap const&, bool, bool) + 4671341204
3  Flutter                        0x4c9f30 std::__1::__function::__func<flutter::UploadRasterImage(sk_sp<SkImage>, fml::WeakPtr<flutter::IOManager>, fml::tracing::TraceFlow const&)::$_3, std::__1::allocator<flutter::UploadRasterImage(sk_sp<SkImage>, fml::WeakPtr<flutter::IOManager>, fml::tracing::TraceFlow const&)::$_3>, void ()>::operator()() + 4674264880
4  Flutter                        0x307024 fml::SyncSwitch::Execute(fml::SyncSwitch::Handlers const&) const + 4672417828
5  Flutter                        0x4c989c std::__1::__function::__func<fml::internal::CopyableLambda<flutter::ImageDecoderSkia::Decode(fml::RefPtr<flutter::ImageDescriptor>, unsigned int, unsigned int, std::__1::function<void (sk_sp<flutter::DlImage>)> const&)::$_1::operator()()::'lambda'()>, std::__1::allocator<fml::internal::CopyableLambda<flutter::ImageDecoderSkia::Decode(fml::RefPtr<flutter::ImageDescriptor>, unsigned int, unsigned int, std::__1::function<void (sk_sp<flutter::DlImage>)> const&)::$_1::operator()()::'lambda'()> >, void ()>::operator()() + 4674263196
6  Flutter                        0x30584c fml::MessageLoopImpl::FlushTasks(fml::FlushType) + 4672411724
7  Flutter                        0x308b48 fml::MessageLoopDarwin::OnTimerFire(__CFRunLoopTimer*, fml::MessageLoopDarwin*) + 4672424776
8  CoreFoundation                 0xce35c __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 32
9  CoreFoundation                 0x8a9d8 __CFRunLoopDoTimer + 940
10 CoreFoundation                 0x2e598 __CFRunLoopDoTimers + 288
11 CoreFoundation                 0x7bfcc __CFRunLoopRun + 1896
12 CoreFoundation                 0x80ed4 CFRunLoopRunSpecific + 612
13 Flutter                        0x308a18 fml::MessageLoopDarwin::Run() + 4672424472
14 Flutter                        0x3083fc void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, fml::Thread::Thread(std::__1::function<void (fml::Thread::ThreadConfig const&)> const&, fml::Thread::ThreadConfig const&)::$_0> >(void*) + 4672422908
15 libsystem_pthread.dylib        0x16cc _pthread_start + 148
16 libsystem_pthread.dylib        0xba4 thread_start + 8
```






```
[✓] Flutter (Channel unknown, 3.0.5, on macOS 12.5.1 21G83 darwin-x64, locale zh-Hans-CN)
    • Flutter version 3.0.5 at /Users/lingoace/environment/flutter
    • Upstream repository unknown
    • Framework revision f1875d570e (4 个月前), 2022-07-13 11:24:16 -0700
    • Engine revision e85ea0e79c
    • Dart version 2.17.6
    • DevTools version 2.12.2
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4)
    • Android SDK at /Users/lingoace/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0-rc4
    • ANDROID_HOME = /Users/lingoace/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.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
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] VS Code (version 1.73.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-x64     • macOS 12.5.1 21G83 darwin-x64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 107.0.5304.110

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

```

</details>


<!--
      Consider also attaching screenshots and/or videos to better
      illustrate the issue.

      You can upload them directly on GitHub.
      Beware that video file size is limited to 10MB.
-->