1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:14:58 +00:00

LibGfx+Userland: Make PNGWriter::encode() return ErrorOr<ByteBuffer>

This is a first step towards handling PNG encoding failures instead of
just falling over and crashing the program.

This initial step will cause encode() to return an error if the final
ByteBuffer copy fails to allocate. There are more potential failures
that will be surfaced by subsequent commits.

Two FIXMEs were killed in the making of this patch. :^)
This commit is contained in:
Andreas Kling 2022-12-05 20:34:27 +01:00 committed by Sam Atkins
parent 95b4ffad39
commit d88c7fee32
9 changed files with 18 additions and 13 deletions

View file

@ -151,11 +151,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
return 0;
}
auto encoded_bitmap = Gfx::PNGWriter::encode(*bitmap);
if (encoded_bitmap.is_empty()) {
auto encoded_bitmap_or_error = Gfx::PNGWriter::encode(*bitmap);
if (encoded_bitmap_or_error.is_error()) {
warnln("Failed to encode PNG");
return 1;
}
auto encoded_bitmap = encoded_bitmap_or_error.release_value();
if (edit_image)
output_path = Core::DateTime::now().to_deprecated_string("/tmp/screenshot-%Y-%m-%d-%H-%M-%S.png"sv);