Commit: 1b18e158025a488e1ba2446ad93c2eb563c11611
Author: Dalai Felinto
Date:   Tue Nov 7 14:06:55 2017 -0200
Branches: blender2.8
https://developer.blender.org/rB1b18e158025a488e1ba2446ad93c2eb563c11611

Sanitize use of BLI_iterator

We now initialize iter.valid as true as part of the main iterator (and manually
when using via Python). And we don't even bother setting iter->current to NULL
if it's invalid. Let's stick to using iter->valid only.

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

M       source/blender/blenkernel/intern/collection.c
M       source/blender/blenkernel/intern/layer.c
M       source/blender/blenlib/BLI_iterator.h
M       source/blender/depsgraph/intern/depsgraph_query.cc
M       source/blender/makesrna/intern/rna_depsgraph.c

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

diff --git a/source/blender/blenkernel/intern/collection.c 
b/source/blender/blenkernel/intern/collection.c
index 2b69c176c39..2a1157cf6b4 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -535,7 +535,6 @@ void BKE_scene_collections_iterator_begin(BLI_Iterator 
*iter, void *data_in)
 
        data->cur = 0;
        iter->current = data->array[data->cur];
-       iter->valid = true;
 }
 
 void BKE_scene_collections_iterator_next(struct BLI_Iterator *iter)
@@ -585,10 +584,10 @@ void BKE_scene_objects_iterator_begin(BLI_Iterator *iter, 
void *data_in)
        BKE_scene_collections_iterator_begin(&data->scene_collection_iter, 
scene);
 
        SceneCollection *sc = data->scene_collection_iter.current;
-       iter->current = sc->objects.first ? ((LinkData 
*)sc->objects.first)->data : NULL;
-       iter->valid = true;
-
-       if (iter->current == NULL) {
+       if (sc->objects.first != NULL) {
+               iter->current = ((LinkData *)sc->objects.first)->data;
+       }
+       else {
                BKE_scene_objects_iterator_next(iter);
        }
 }
diff --git a/source/blender/blenkernel/intern/layer.c 
b/source/blender/blenkernel/intern/layer.c
index 2e1495b2e11..3544cf02afb 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -1674,7 +1674,6 @@ static void object_bases_iterator_begin(BLI_Iterator 
*iter, void *data_in, const
                return;
        }
 
-       iter->valid = true;
        iter->data = base;
 
        if ((base->flag & flag) == 0) {
@@ -1698,7 +1697,6 @@ static void object_bases_iterator_next(BLI_Iterator 
*iter, const int flag)
                base = base->next;
        }
 
-       iter->current = NULL;
        iter->valid = false;
 }
 
@@ -1800,7 +1798,6 @@ void BKE_renderable_objects_iterator_begin(BLI_Iterator 
*iter, void *data_in)
 
        data->iter.set = NULL;
 
-       iter->valid = true;
        iter->data = data_in;
        BKE_renderable_objects_iterator_next(iter);
 }
@@ -1855,7 +1852,6 @@ void BKE_renderable_objects_iterator_next(BLI_Iterator 
*iter)
                return;
        }
 
-       iter->current = NULL;
        iter->valid = false;
 }
 
diff --git a/source/blender/blenlib/BLI_iterator.h 
b/source/blender/blenlib/BLI_iterator.h
index d8929b6e73a..49a3cea58bc 100644
--- a/source/blender/blenlib/BLI_iterator.h
+++ b/source/blender/blenlib/BLI_iterator.h
@@ -43,12 +43,11 @@ typedef void (*IteratorBeginCb)(BLI_Iterator *iter, void 
*data_in);
        IteratorCb callback_end_func = callback_end;                            
         \
        BLI_Iterator iter_macro;                                                
         \
        iter_macro.skip = false;                                                
         \
-       iter_macro.valid = false;                                               
         \
+       iter_macro.valid = true;                                                
         \
        for (callback_begin(&iter_macro, (_data_in));                           
         \
             iter_macro.valid;                                                  
         \
             callback_next(&iter_macro))                                        
         \
        {                                                                       
         \
-               BLI_assert(iter_macro.valid);                                   
             \
                if (iter_macro.skip) {                                          
             \
                        iter_macro.skip = false;                                
                 \
                        continue;                                               
                 \
diff --git a/source/blender/depsgraph/intern/depsgraph_query.cc 
b/source/blender/depsgraph/intern/depsgraph_query.cc
index 84c8c873860..e950aa58112 100644
--- a/source/blender/depsgraph/intern/depsgraph_query.cc
+++ b/source/blender/depsgraph/intern/depsgraph_query.cc
@@ -259,7 +259,6 @@ void DEG_objects_iterator_begin(BLI_Iterator *iter, 
DEGObjectsIteratorData *data
        Depsgraph *graph = data->graph;
 
        iter->data = data;
-       iter->valid = true;
 
        DEG_evaluation_context_init(&data->eval_ctx, DAG_EVAL_RENDER);
 
@@ -275,7 +274,7 @@ void DEG_objects_iterator_begin(BLI_Iterator *iter, 
DEGObjectsIteratorData *data
        DEG::IDDepsNode *id_node = (DEG::IDDepsNode *) 
BLI_ghashIterator_getValue(&data->gh_iter);
        deg_objects_iterator_step(iter, id_node);
 
-       if (iter->valid && iter->skip) {
+       if (iter->skip) {
                DEG_objects_iterator_next(iter);
        }
 }
@@ -299,7 +298,6 @@ void DEG_objects_iterator_next(BLI_Iterator *iter)
 
                BLI_ghashIterator_step(&data->gh_iter);
                if (BLI_ghashIterator_done(&data->gh_iter)) {
-                       iter->current = NULL;
                        iter->valid = false;
                        return;
                }
@@ -307,7 +305,7 @@ void DEG_objects_iterator_next(BLI_Iterator *iter)
                DEG::IDDepsNode *id_node = (DEG::IDDepsNode *) 
BLI_ghashIterator_getValue(&data->gh_iter);
 
                deg_objects_iterator_step(iter, id_node);
-       } while (iter->valid && iter->skip);
+       } while (iter->skip);
 }
 
 void DEG_objects_iterator_end(BLI_Iterator *iter)
diff --git a/source/blender/makesrna/intern/rna_depsgraph.c 
b/source/blender/makesrna/intern/rna_depsgraph.c
index f5b4d9cde0f..04c8352833e 100644
--- a/source/blender/makesrna/intern/rna_depsgraph.c
+++ b/source/blender/makesrna/intern/rna_depsgraph.c
@@ -154,6 +154,7 @@ static void 
rna_Depsgraph_objects_begin(CollectionPropertyIterator *iter, Pointe
        data->graph = (Depsgraph *)ptr->data;
        data->flag = DEG_OBJECT_ITER_FLAG_SET;
 
+       ((BLI_Iterator *)iter->internal.custom)->valid = true;
        DEG_objects_iterator_begin(iter->internal.custom, data);
        iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
 }
@@ -190,6 +191,7 @@ static void 
rna_Depsgraph_duplis_begin(CollectionPropertyIterator *iter, Pointer
        data->graph = (Depsgraph *)ptr->data;
        data->flag = DEG_OBJECT_ITER_FLAG_ALL;
 
+       ((BLI_Iterator *)iter->internal.custom)->valid = true;
        DEG_objects_iterator_begin(iter->internal.custom, data);
        iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to