Repository: flutter
Issue: Exception: Image upload failed due to loss of GPU access on iOS Devices on 3.27.1
Labels: c: regression,platform-ios,engine,a: images,has reproducible steps,P1,team-ios,triaged-ios,found in release: 3.27

### Steps to reproduce

Reproducible with flutter 3.27.1, introduced in commit fc011960a2 

Not reproducible with parent commit e466195f42 and not reproducible on 3.24.5

1. Run the sample app on an iOS physical device using Flutter version 3.27.1
2. Pan down on the main page
3. Tap on the next arrow to go to the next page in the sample app
4. Move the app to the background by putting another app in the foreground
5. Move the sample app back to the foreground
6. Observe console errors `Exception: Image upload failed due to loss of GPU access.`

related: #159397 and fluttercandies/extended_image#724

attempting to reproduce with a binary search on various flutter commits, the first commit introducing the issue is commit fc011960a2 
note that today's master branch commit 2d17299f20f3 does not exhibit the issue

### Expected results

Expected no exceptions

### Actual results

After putting app in foreground after putting it in background, images in the UI fail to render with the following error to console:

```
Exception: Image upload failed due to loss of GPU access.
```

With an "All Exceptions" breakpoint I get the following stack trace:

```
MultiFrameImageStreamCompleter._decodeNextFrameAndSchedule (development/flutter/packages/flutter/lib/src/painting/image_stream.dart:1064)
<asynchronous gap> (Unknown Source:0)
```

### Code sample

<details open><summary>Sample app that loads several images</summary>

```dart
import 'package:extended_image/extended_image.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
        useMaterial3: true,
      ),
      debugShowCheckedModeBanner: false,
      home: const MyHomePage(title: 'Loss of GPU Access Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    final int imageWidth = MediaQuery.sizeOf(context).width.toInt();
    final int imageHeight = 200;
    final urls = List.generate(50, (i) {
      return 'https://picsum.photos/seed/$i/$imageWidth/$imageHeight';
    });

    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
        actions: [
          IconButton(
            icon: const Icon(Icons.navigate_next),
            tooltip: 'Next',
            onPressed: () {
              Navigator.of(context).push(
                MaterialPageRoute(builder: (context) => const SecondScreen()),
              );
            },
          ),
        ],
      ),
      body: ListView.builder(
        itemCount: urls.length,
        // No error occurs when removing cacheExtent
        cacheExtent: MediaQuery.sizeOf(context).height * 5,
        itemBuilder: (context, index) {
          if (index == 0) {
            return Wrap(
              children: [
                Text(
                  'To reproduce: Scroll down, then use the next button, then put app in background, bring to foreground',
                ),
              ],
            );
          }
          return SizedBox(
            width: double.infinity,
            height: imageHeight.toDouble(),
            child: ExtendedImage.network(urls[index]),
          );
        },
      ),
    );
  }
}

class SecondScreen extends StatefulWidget {
  const SecondScreen({super.key});

  @override
  State<SecondScreen> createState() => SecondScreenState();
}

class SecondScreenState extends State<SecondScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text('Second Page'),
      ),
      body: Center(child: Text('Second Page')),
    );
  }
}
```

</details>


### Screenshots or Video

no screenshots

### Logs

<details open><summary>Logs</summary>

```console
════════ Exception caught by image resource service ════════════════════════════
Exception: Image upload failed due to loss of GPU access.
════════════════════════════════════════════════════════════════════════════════
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
bug % flutter doctor -v
[✓] Flutter (Channel stable, 3.27.1, on macOS 14.6 23G80 darwin-arm64, locale en-CA)
    • Flutter version 3.27.1 on channel stable at /Users/dgreen/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 17025dd882 (3 weeks ago), 2024-12-17 03:23:09 +0900
    • Engine revision cb4b5fff73
    • Dart version 3.6.0
    • DevTools version 2.40.2

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at /Users/dgreen/Library/Android/sdk
    • Platform android-35, build-tools 35.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16B40
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.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 21.0.3+-79915917-b509.11)

[✓] IntelliJ IDEA Community Edition (version 2024.1.7)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • 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

[✓] VS Code (version 1.96.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.102.0

[✓] Connected device (5 available)
    • David’s iPhone (mobile)         • 00008130-000C5C322179001C            • ios            • iOS 18.1.1 22B91
    • iPhone 16 Pro Max (mobile)      • 485BC19C-49C5-47D9-802A-43749F36014E • ios            • com.apple.CoreSimulator.SimRuntime.iOS-18-2 (simulator)
    • macOS (desktop)                 • macos                                • darwin-arm64   • macOS 14.6 23G80 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin         • macOS 14.6 23G80 darwin-arm64
    • Chrome (web)                    • chrome                               • web-javascript • Google Chrome 131.0.6778.205
    ! Error: Browsing on the local area network for Old 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.

• No issues found!
```

</details>