[Bf-blender-cvs] [bd03fe1ab0d] master: Cleanup: avoid Operator.customdata cast which could lead to errors

Campbell Barton noreply at git.blender.org
Tue Feb 25 11:32:13 CET 2020


Commit: bd03fe1ab0d09aa7bb29bdcd3d57db772b1dadbd
Author: Campbell Barton
Date:   Tue Feb 25 20:32:20 2020 +1100
Branches: master
https://developer.blender.org/rBbd03fe1ab0d09aa7bb29bdcd3d57db772b1dadbd

Cleanup: avoid Operator.customdata cast which could lead to errors

Both save and save-as share utility functions which
cast from customdata in an error prone way.

Avoid this by passing image format data directly.

===================================================================

M	source/blender/editors/space_image/image_ops.c

===================================================================

diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index d6355bb88fe..a3fa03b18b7 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -2043,12 +2043,14 @@ static int image_save_options_init(Main *bmain,
   return (ibuf != NULL);
 }
 
-static void image_save_options_from_op(Main *bmain, ImageSaveOptions *opts, wmOperator *op)
+static void image_save_options_from_op(Main *bmain,
+                                       ImageSaveOptions *opts,
+                                       wmOperator *op,
+                                       ImageFormatData *imf)
 {
-  if (op->customdata) {
-    ImageSaveData *isd = op->customdata;
+  if (imf) {
     BKE_color_managed_view_settings_free(&opts->im_format.view_settings);
-    opts->im_format = isd->im_format;
+    opts->im_format = *imf;
   }
 
   if (RNA_struct_property_is_set(op->ptr, "filepath")) {
@@ -2111,10 +2113,12 @@ static int image_save_as_exec(bContext *C, wmOperator *op)
 
   Image *image = NULL;
   ImageUser *iuser = NULL;
+  ImageFormatData *imf = NULL;
   if (op->customdata) {
     ImageSaveData *isd = op->customdata;
     image = isd->image;
     iuser = isd->iuser;
+    imf = &isd->im_format;
   }
   else {
     image = image_from_context(C);
@@ -2127,7 +2131,7 @@ static int image_save_as_exec(bContext *C, wmOperator *op)
    * these should be set on invoke or by the caller. */
   image_save_options_init(bmain, &opts, image, iuser, false, false);
 
-  image_save_options_from_op(bmain, &opts, op);
+  image_save_options_from_op(bmain, &opts, op, imf);
   opts.do_newpath = true;
 
   save_image_op(bmain, image, iuser, op, &opts);
@@ -2371,7 +2375,7 @@ static int image_save_exec(bContext *C, wmOperator *op)
   if (image_save_options_init(bmain, &opts, image, iuser, false, false) == 0) {
     return OPERATOR_CANCELLED;
   }
-  image_save_options_from_op(bmain, &opts, op);
+  image_save_options_from_op(bmain, &opts, op, NULL);
 
   if (BLI_exists(opts.filepath) && BLI_file_is_writable(opts.filepath)) {
     if (save_image_op(bmain, image, iuser, op, &opts)) {



More information about the Bf-blender-cvs mailing list