New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flutter crashes when loading very large files with Image.file widget on Windows #112881
Comments
Given that there's generally little utility in loading/displaying a whole 3.6GB image (even if it is a graphical image), I'd suggest the best case is to avoid doing it at all and rely on a beefy server-side thumbnailing service of some sort. That said, looks like the file is local here, and the issue relates to desktop machines. Have you tried playing with the |
We don't have a need to actually render the image. We would just like to be able to fail gracefully with the |
It's still crashing for me when using this code sample: import 'dart:io';
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 Code Sample',
home: Scaffold(
body: Image.file(
width: 100,
height: 100,
cacheWidth: 100,
cacheHeight: 100,
File('<path-to-file>'),
errorBuilder: (context, error, stackTrace) => Text(error.toString()),
),
),
);
}
} |
Ah so to be clear this is more about failing gracefully with an error on non-image files, than crashing when loading extremely large (valid) image files. Thanks for clarifying. |
It already gracefully fails on non-image files. We would like it to also gracefully fail when loading extremely large files (image or not) |
Definitely curious as to why we're crashing (investigating that now), but you might want a better solution that does not involve loading files into memory that definitely aren't images - large or otherwise. Here is a gist of how that could be done: https://gist.github.com/jonahwilliams/56bc6212445d813a8579e6a395327a29 |
The magic number is INT_MAX bytes (2147483647), dart issue is dart-lang/sdk#50129 |
I've updated the gist with that number and fixed the equality implementation |
Fix is pending at #112892, which will both improve the performance of FileImage and prevent this particular crash |
… file type) (#112892) Update FileImage to use the new ImmutableBuffer.fromFilePath constructor to avoid loading bytes through the Dart heap. As a side effect, tis fixes #112881 which prevents dart:io from opening a file larger than INT_MAX bytes on windows. For files that are not exactly a dart:io file, we still use the old method of calling loadBytes() in order to not make this a breaking change.
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 |
Internal bug: b/248028795
Steps to Reproduce
<path-to-file>
to the path of a very large fileflutter run
on the code sampleExpected results:
errorBuilder
should return appropriate error. On macOS, this works and shows the following in the app:Actual results:
On Windows, the Flutter app just crashes
Code sample
Logs
The text was updated successfully, but these errors were encountered: