Fix T50736: Zero streaks in Glare node.
authorBastien Montagne <montagne29@wanadoo.fr>
Thu, 23 Feb 2017 09:39:51 +0000 (10:39 +0100)
committerBastien Montagne <montagne29@wanadoo.fr>
Thu, 23 Feb 2017 09:39:51 +0000 (10:39 +0100)
Please never, ever use same DNA var for two different things. Even worse
if they do not have same type and ranges!

This is only ensuring issues (as described in report, but also if
animating both RNA props using same DNA var... yuck).

And we were not even saving any byte in DNA, could reuse some padding
there to store the two new needed vars (yes, two, since we cannot re-use
existing one if we want to keep backward *and* forward compatibility).

source/blender/blenloader/intern/versioning_270.c
source/blender/blenloader/intern/writefile.c
source/blender/compositor/operations/COM_GlareSimpleStarOperation.cpp
source/blender/compositor/operations/COM_GlareStreaksOperation.cpp
source/blender/makesdna/DNA_node_types.h
source/blender/makesrna/intern/rna_nodetree.c
source/blender/nodes/composite/nodes/node_composite_glare.c

index 6235ebf28ee4e56ec4ba83c0412d08a807f1b46a..7106cf607212a10f9e8dbf45a6c1daa43b9258a5 100644 (file)
@@ -1575,6 +1575,29 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
                        }
                }
 
+               /* Fix for T50736, Glare comp node using same var for two different things. */
+               if (!DNA_struct_elem_find(fd->filesdna, "NodeGlare", "char", "star_45")) {
+                       FOREACH_NODETREE(main, ntree, id) {
+                               if (ntree->type == NTREE_COMPOSIT) {
+                                       ntreeSetTypes(NULL, ntree);
+                                       for (bNode *node = ntree->nodes.first; node; node = node->next) {
+                                               if (node->type == CMP_NODE_GLARE) {
+                                                       NodeGlare *ndg = node->storage;
+                                                       switch (ndg->type) {
+                                                               case 2:  /* Grrrr! magic numbers :( */
+                                                                       ndg->streaks = ndg->angle;
+                                                                       break;
+                                                               case 0:
+                                                                       ndg->star_45 = ndg->angle != 0;
+                                                                       break;
+                                                               default:
+                                                                       break;
+                                                       }
+                                               }
+                                       }
+                               }
+                       } FOREACH_NODETREE_END
+               }
        }
 }
 
index 998d4161c2f95a4568eb7109b20ca312216f7a98..38a032f490790f287e99902922eb98b306249fe4 100644 (file)
@@ -1026,6 +1026,25 @@ static void write_nodetree(WriteData *wd, bNodeTree *ntree)
                        {
                                /* pass */
                        }
+                       else if ((ntree->type == NTREE_COMPOSIT) && (node->type == CMP_NODE_GLARE)) {
+                               /* Simple forward compat for fix for T50736.
+                                * Not ideal (there is no ideal solution here), but should do for now. */
+                               NodeGlare *ndg = node->storage;
+                               /* Not in undo case. */
+                               if (!wd->current) {
+                                       switch (ndg->type) {
+                                               case 2:  /* Grrrr! magic numbers :( */
+                                                       ndg->angle = ndg->streaks;
+                                                       break;
+                                               case 0:
+                                                       ndg->angle = ndg->star_45;
+                                                       break;
+                                               default:
+                                                       break;
+                                       }
+                               }
+                               writestruct_id(wd, DATA, node->typeinfo->storagename, 1, node->storage);
+                       }
                        else {
                                writestruct_id(wd, DATA, node->typeinfo->storagename, 1, node->storage);
                        }
index 957ac5af7487575c378fc7d3aac46d09fba1981a..57aa3a1bac2b8b1e306e7e307af06324b40b317e 100644 (file)
@@ -44,18 +44,18 @@ void GlareSimpleStarOperation::generateGlare(float *data, MemoryBuffer *inputTil
                                xp = x + i;
                                tbuf1->read(c, x, y);
                                mul_v3_fl(c, f1);
-                               tbuf1->read(tc, (settings->angle ? xm : x), ym);
+                               tbuf1->read(tc, (settings->star_45 ? xm : x), ym);
                                madd_v3_v3fl(c, tc, f2);
-                               tbuf1->read(tc, (settings->angle ? xp : x), yp);
+                               tbuf1->read(tc, (settings->star_45 ? xp : x), yp);
                                madd_v3_v3fl(c, tc, f2);
                                c[3] = 1.0f;
                                tbuf1->writePixel(x, y, c);
 
                                tbuf2->read(c, x, y);
                                mul_v3_fl(c, f1);
-                               tbuf2->read(tc, xm, (settings->angle ? yp : y));
+                               tbuf2->read(tc, xm, (settings->star_45 ? yp : y));
                                madd_v3_v3fl(c, tc, f2);
-                               tbuf2->read(tc, xp, (settings->angle ? ym : y));
+                               tbuf2->read(tc, xp, (settings->star_45 ? ym : y));
                                madd_v3_v3fl(c, tc, f2);
                                c[3] = 1.0f;
                                tbuf2->writePixel(x, y, c);
@@ -73,18 +73,18 @@ void GlareSimpleStarOperation::generateGlare(float *data, MemoryBuffer *inputTil
                                xp = x + i;
                                tbuf1->read(c, x, y);
                                mul_v3_fl(c, f1);
-                               tbuf1->read(tc, (settings->angle ? xm : x), ym);
+                               tbuf1->read(tc, (settings->star_45 ? xm : x), ym);
                                madd_v3_v3fl(c, tc, f2);
-                               tbuf1->read(tc, (settings->angle ? xp : x), yp);
+                               tbuf1->read(tc, (settings->star_45 ? xp : x), yp);
                                madd_v3_v3fl(c, tc, f2);
                                c[3] = 1.0f;
                                tbuf1->writePixel(x, y, c);
 
                                tbuf2->read(c, x, y);
                                mul_v3_fl(c, f1);
-                               tbuf2->read(tc, xm, (settings->angle ? yp : y));
+                               tbuf2->read(tc, xm, (settings->star_45 ? yp : y));
                                madd_v3_v3fl(c, tc, f2);
-                               tbuf2->read(tc, xp, (settings->angle ? ym : y));
+                               tbuf2->read(tc, xp, (settings->star_45 ? ym : y));
                                madd_v3_v3fl(c, tc, f2);
                                c[3] = 1.0f;
                                tbuf2->writePixel(x, y, c);
index da6076337b44a0a200a5ab66a6da0dd1050b8302..535f2952e5dccae4d2b23e578cfc972d706fb932 100644 (file)
@@ -28,7 +28,7 @@ void GlareStreaksOperation::generateGlare(float *data, MemoryBuffer *inputTile,
        int x, y, n;
        unsigned int nump = 0;
        float c1[4], c2[4], c3[4], c4[4];
-       float a, ang = DEG2RADF(360.0f) / (float)settings->angle;
+       float a, ang = DEG2RADF(360.0f) / (float)settings->streaks;
 
        int size = inputTile->getWidth() * inputTile->getHeight();
        int size4 = size * 4;
index fd601e555503c2d25a3415584ed4ff296441e8d0..47677e50451ef550b0a43ccdbaa4f6ca6398e4ef 100644 (file)
@@ -668,7 +668,8 @@ typedef struct NodeScriptDict {
 /* qdn: glare node */
 typedef struct NodeGlare {
        char quality, type, iter;
-       char angle, pad_c1, size, pad[2];
+       /* XXX angle is only kept for backward/forward compatibility, was used for two different things, see T50736. */
+       char angle DNA_DEPRECATED, pad_c1, size, star_45, streaks;
        float colmod, mix, threshold, fade;
        float angle_ofs, pad_f1;
 } NodeGlare;
index b35142f2a58efad3dfcafbe93dd2519ff5546e59..784004182ddcdf1282c60aabefe7c8a4a1c56b62 100644 (file)
@@ -5721,8 +5721,8 @@ static void def_cmp_glare(StructRNA *srna)
        RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
        
        prop = RNA_def_property(srna, "streaks", PROP_INT, PROP_NONE);
-       RNA_def_property_int_sdna(prop, NULL, "angle");
-       RNA_def_property_range(prop, 2, 16);
+       RNA_def_property_int_sdna(prop, NULL, "streaks");
+       RNA_def_property_range(prop, 1, 16);
        RNA_def_property_ui_text(prop, "Streaks", "Total number of streaks");
        RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
        
@@ -5739,7 +5739,7 @@ static void def_cmp_glare(StructRNA *srna)
        RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
        
        prop = RNA_def_property(srna, "use_rotate_45", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_sdna(prop, NULL, "angle", 0);
+       RNA_def_property_boolean_sdna(prop, NULL, "star_45", 0);
        RNA_def_property_ui_text(prop, "Rotate 45", "Simple star filter: add 45 degree rotation offset");
        RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
        
index c512ea49586a5d08031117cb76320e51ee78675d..76020e55463c7f82ca75ba000944bcb76ab0cfe4 100644 (file)
@@ -50,7 +50,8 @@ static void node_composit_init_glare(bNodeTree *UNUSED(ntree), bNode *node)
        ndg->colmod = 0.25;
        ndg->mix = 0;
        ndg->threshold = 1;
-       ndg->angle = 4;
+       ndg->star_45 = true;
+       ndg->streaks = 4;
        ndg->angle_ofs = 0.0f;
        ndg->fade = 0.9;
        ndg->size = 8;