Render API: Support arbitrary length for custom image metadata fields
authorLukas Stockner <lukas.stockner@freenet.de>
Thu, 8 Nov 2018 00:05:55 +0000 (01:05 +0100)
committerLukas Stockner <lukas.stockner@freenet.de>
Thu, 8 Nov 2018 00:07:54 +0000 (01:07 +0100)
source/blender/blenkernel/intern/image.c
source/blender/makesrna/intern/rna_render.c

index d01650e320401d8daf3c12e4827571dafcc6d034..1d209dec9351341b903fcdce68d08fddba10f99c 100644 (file)
@@ -1612,7 +1612,7 @@ typedef struct StampDataCustomField {
        struct StampDataCustomField *next, *prev;
        /* TODO(sergey): Think of better size here, maybe dynamically allocated even. */
        char key[512];
-       char value[512];
+       char *value;
        /* TODO(sergey): Support non-string values. */
 } StampDataCustomField;
 
@@ -2177,12 +2177,9 @@ void BKE_stamp_info_callback(void *data, struct StampData *stamp_data, StampCall
        CALL(rendertime, "RenderTime");
        CALL(memory, "Memory");
 
-       for (StampDataCustomField *custom_field = stamp_data->custom_fields.first;
-            custom_field != NULL;
-            custom_field = custom_field->next)
-       {
+       LISTBASE_FOREACH(StampDataCustomField *, custom_field, &stamp_data->custom_fields) {
                if (noskip || custom_field->value[0]) {
-                       callback(data, custom_field->key, custom_field->value, sizeof(custom_field->value));
+                       callback(data, custom_field->key, custom_field->value, strlen(custom_field->value) + 1);
                }
        }
 
@@ -2199,7 +2196,7 @@ void BKE_render_result_stamp_data(RenderResult *rr, const char *key, const char
        StampDataCustomField *field = MEM_mallocN(sizeof(StampDataCustomField),
                                                  "StampData Custom Field");
        STRNCPY(field->key, key);
-       STRNCPY(field->value, value);
+       field->value = BLI_strdup(value);
        BLI_addtail(&stamp_data->custom_fields, field);
 }
 
@@ -2208,6 +2205,9 @@ void BKE_stamp_data_free(struct StampData *stamp_data)
        if (stamp_data == NULL) {
                return;
        }
+       LISTBASE_FOREACH(StampDataCustomField *, custom_field, &stamp_data->custom_fields) {
+               MEM_freeN(custom_field->value);
+       }
        BLI_freelistN(&stamp_data->custom_fields);
        MEM_freeN(stamp_data);
 }
index 513717a9e461fca2edaf4d591802df0c4b6d5603..b516accbf1efccaf7a3ba9495ea47dac585f20c6 100644 (file)
@@ -801,7 +801,7 @@ static void rna_def_render_result(BlenderRNA *brna)
        RNA_def_function_ui_description(func, "Add engine-specific stamp data to the result");
        parm = RNA_def_string(func, "field", NULL, 1024, "Field", "Name of the stamp field to add");
        RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
-       parm = RNA_def_string(func, "value", NULL, 1024, "Value", "Value of the stamp data");
+       parm = RNA_def_string(func, "value", NULL, 0, "Value", "Value of the stamp data");
        RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
 
        RNA_define_verify_sdna(0);