Commit 28f8e595 for libheif
commit 28f8e59545e7da492a648252167b70513992ede4
Author: Dirk Farin <dirk.farin@gmail.com>
Date: Mon Apr 20 14:52:28 2026 +0200
fix: set primary image (unci) after checking for error result
diff --git a/libheif/api/libheif/heif_uncompressed.cc b/libheif/api/libheif/heif_uncompressed.cc
index ae3edef5..6dd876bc 100644
--- a/libheif/api/libheif/heif_uncompressed.cc
+++ b/libheif/api/libheif/heif_uncompressed.cc
@@ -808,12 +808,6 @@ heif_error heif_context_add_empty_unci_image(heif_context* ctx,
Result<std::shared_ptr<ImageItem_uncompressed>> unciImageResult;
unciImageResult = ImageItem_uncompressed::add_unci_item(ctx->context.get(), parameters, encoding_options, prototype->image);
- // mark the new image as primary image
-
- if (ctx->context->is_primary_image_set() == false) {
- ctx->context->set_primary_image(*unciImageResult);
- }
-
if (encoding_options) {
heif_encoding_options_free(default_options);
}
@@ -822,6 +816,12 @@ heif_error heif_context_add_empty_unci_image(heif_context* ctx,
return unciImageResult.error_struct(ctx->context.get());
}
+ // mark the new image as primary image
+
+ if (ctx->context->is_primary_image_set() == false) {
+ ctx->context->set_primary_image(*unciImageResult);
+ }
+
assert(out_unci_image_handle);
*out_unci_image_handle = new heif_image_handle;
(*out_unci_image_handle)->image = *unciImageResult;