From 785e96a11d452b2ea67cfc0be573ccd0f5cbdb8f Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 18 Sep 2017 19:18:02 +0200 Subject: Fix (irc-reported by @sergey) invalid precision value in a float RNA property. Maximum allowed UI float precision value is 6 (which means 7 digits). Will change code checking on that in next commit. --- source/blender/makesrna/intern/rna_modifier.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index e53237ae2c1..96b88d98270 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -1974,7 +1974,7 @@ static void rna_def_modifier_boolean(BlenderRNA *brna) prop = RNA_def_property(srna, "double_threshold", PROP_FLOAT, PROP_DISTANCE); RNA_def_property_float_sdna(prop, NULL, "double_threshold"); RNA_def_property_range(prop, 0, 1.0f); - RNA_def_property_ui_range(prop, 0, 1, 0.0001, 7); + RNA_def_property_ui_range(prop, 0, 1, 0.0001, 6); RNA_def_property_ui_text(prop, "Overlap Threshold", "Threshold for checking overlapping geometry"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); } -- cgit v1.2.3 From bb4a12914fad3cb1867e34ff01a5ddc9f761e7f0 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 18 Sep 2017 19:50:40 +0200 Subject: Add some security checks against future bad float UIprecision values. This commit and previous one should be backported to 2.79a should we release it. --- source/blender/editors/include/UI_interface.h | 2 +- source/blender/editors/interface/interface.c | 3 +++ source/blender/makesrna/intern/rna_define.c | 25 ++++++------------------- 3 files changed, 10 insertions(+), 20 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 9376de8c095..e14a3a3ff0a 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -996,7 +996,7 @@ void uiItemsFullEnumO( struct IDProperty *properties, int context, int flag); void uiItemsFullEnumO_items( uiLayout *layout, struct wmOperatorType *ot, PointerRNA ptr, PropertyRNA *prop, - IDProperty *properties, int context, int flag, + struct IDProperty *properties, int context, int flag, const EnumPropertyItem *item_array, int totitem); void uiItemL(uiLayout *layout, const char *name, int icon); /* label */ diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index fd5159bb76c..5c05fc8c530 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -488,6 +488,9 @@ static int ui_but_calc_float_precision(uiBut *but, double value) else if (prec == -1) { prec = (but->hardmax < 10.001f) ? 3 : 2; } + else { + CLAMP(prec, 0, UI_PRECISION_FLOAT_MAX); + } return UI_calc_float_precision(prec, value); } diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index 0e91c158669..118dd0b15de 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -44,6 +44,8 @@ #include "BLT_translation.h" +#include "UI_interface.h" /* For things like UI_PRECISION_FLOAT_MAX... */ + #include "RNA_define.h" #include "rna_internal.h" @@ -1405,13 +1407,13 @@ void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, bool consecutive) * For ints, whole values are used. * * \param precision The number of zeros to show - * (as a whole number - common range is 1 - 6), see PRECISION_FLOAT_MAX + * (as a whole number - common range is 1 - 6), see UI_PRECISION_FLOAT_MAX */ void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision) { StructRNA *srna = DefRNA.laststruct; -#ifdef DEBUG +#ifndef NDEBUG if (min > max) { fprintf(stderr, "%s: \"%s.%s\", min > max.\n", __func__, srna->identifier, prop->identifier); @@ -1424,8 +1426,8 @@ void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double DefRNA.error = 1; } - if (precision < -1 || precision > 10) { - fprintf(stderr, "%s: \"%s.%s\", step outside range.\n", + if (precision < -1 || precision > UI_PRECISION_FLOAT_MAX) { + fprintf(stderr, "%s: \"%s.%s\", precision outside range.\n", __func__, srna->identifier, prop->identifier); DefRNA.error = 1; } @@ -1447,21 +1449,6 @@ void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double fprop->softmax = (float)max; fprop->step = (float)step; fprop->precision = (int)precision; -#if 0 /* handy but annoying */ - if (DefRNA.preprocess) { - /* check we're not over PRECISION_FLOAT_MAX */ - if (fprop->precision > 6) { - fprintf(stderr, "%s: \"%s.%s\", precision value over maximum.\n", - __func__, srna->identifier, prop->identifier); - DefRNA.error = 1; - } - else if (fprop->precision < 1) { - fprintf(stderr, "%s: \"%s.%s\", precision value under minimum.\n", - __func__, srna->identifier, prop->identifier); - DefRNA.error = 1; - } - } -#endif break; } default: -- cgit v1.2.3 From 9a2f7dd77b38504d77b1b058072194496fdc91c9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 19 Sep 2017 14:25:37 +1000 Subject: Correct recent error in boolean quad split check --- source/blender/bmesh/intern/bmesh_polygon.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source/blender') diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c index f0023470099..7b9d17b27b5 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.c +++ b/source/blender/bmesh/intern/bmesh_polygon.c @@ -1523,7 +1523,7 @@ void BM_mesh_calc_tessellation_beauty(BMesh *bm, BMLoop *(*looptris)[3], int *r_ * Use #BLI_polyfill_beautify_quad_rotate_calc since we have the normal. */ #if 0 - const bool split_24 = (BM_verts_calc_rotate_beauty( + const bool split_13 = (BM_verts_calc_rotate_beauty( l_v1->v, l_v2->v, l_v3->v, l_v4->v, 0, 0) < 0.0f); #else float axis_mat[3][3], v_quad[4][2]; @@ -1533,13 +1533,13 @@ void BM_mesh_calc_tessellation_beauty(BMesh *bm, BMLoop *(*looptris)[3], int *r_ mul_v2_m3v3(v_quad[2], axis_mat, l_v3->v->co); mul_v2_m3v3(v_quad[3], axis_mat, l_v4->v->co); - const bool split_24 = BLI_polyfill_beautify_quad_rotate_calc( + const bool split_13 = BLI_polyfill_beautify_quad_rotate_calc( v_quad[0], v_quad[1], v_quad[2], v_quad[3]) < 0.0f; #endif BMLoop **l_ptr_a = looptris[i++]; BMLoop **l_ptr_b = looptris[i++]; - if (split_24 == 0) { + if (split_13) { l_ptr_a[0] = l_v1; l_ptr_a[1] = l_v2; l_ptr_a[2] = l_v3; -- cgit v1.2.3 From 36f5972ed01f4a1f01b42d9439c151e7c69b9afa Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 19 Sep 2017 15:03:58 +1000 Subject: Avoid bias when calculating quad split direction Some error checks weren't being done in both directions when calculating the best split direction for a quad. --- .../blender/blenlib/intern/polyfill2d_beautify.c | 40 ++++++++++++---------- 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenlib/intern/polyfill2d_beautify.c b/source/blender/blenlib/intern/polyfill2d_beautify.c index de5f7f86bee..287fe3c817e 100644 --- a/source/blender/blenlib/intern/polyfill2d_beautify.c +++ b/source/blender/blenlib/intern/polyfill2d_beautify.c @@ -121,6 +121,10 @@ BLI_INLINE bool is_boundary_edge(unsigned int i_a, unsigned int i_b, const unsig * Assuming we have 2 triangles sharing an edge (2 - 4), * check if the edge running from (1 - 3) gives better results. * + * \param lock_degenerate: Use to avoid rotating out of a degenerate state. + * - When true, an existing zero area face on either side of the (2 - 4) split will return a positive value. + * - When false, the check must be non-biased towards either split direction. + * * \return (negative number means the edge can be rotated, lager == better). */ float BLI_polyfill_beautify_quad_rotate_calc_ex( @@ -129,8 +133,6 @@ float BLI_polyfill_beautify_quad_rotate_calc_ex( { /* not a loop (only to be able to break out) */ do { - bool is_zero_a, is_zero_b; - const float area_2x_234 = cross_tri_v2(v2, v3, v4); const float area_2x_241 = cross_tri_v2(v2, v4, v1); @@ -142,25 +144,27 @@ float BLI_polyfill_beautify_quad_rotate_calc_ex( (ELEM(v3, v1, v2, v4) == false) && (ELEM(v4, v1, v2, v3) == false)); - if (lock_degenerate) { - is_zero_a = (fabsf(area_2x_234) <= FLT_EPSILON); - is_zero_b = (fabsf(area_2x_241) <= FLT_EPSILON); - - if (is_zero_a && is_zero_b) { - break; - } - } - - /* one of the tri's was degenerate, check we're not rotating - * into a different degenerate shape or flipping the face */ - if ((fabsf(area_2x_123) <= FLT_EPSILON) || (fabsf(area_2x_134) <= FLT_EPSILON)) { - /* one of the new rotations is degenerate */ + /* + * Test for unusable (1-3) state. + * - Area sign flipping to check faces aren't going to point in opposite directions. + * - Area epsilon check that the one of the faces won't be zero area. + */ + if (((area_2x_123 >= 0.0f) != (area_2x_134 >= 0.0f)) || + (fabsf(area_2x_123) <= FLT_EPSILON) || (fabsf(area_2x_134) <= FLT_EPSILON)) + { break; } - if ((area_2x_123 >= 0.0f) != (area_2x_134 >= 0.0f)) { - /* rotation would cause flipping */ - break; + /* Test for unusable (2-4) state (same as above). */ + if (((area_2x_234 >= 0.0f) != (area_2x_241 >= 0.0f)) || + ((fabsf(area_2x_234) <= FLT_EPSILON) || (fabsf(area_2x_241) <= FLT_EPSILON))) + { + if (lock_degenerate) { + break; + } + else { + return -FLT_MAX; /* always rotate */ + } } { -- cgit v1.2.3 From 7177e0ac3e7a5b018756c163a2ecf9ce2e5e6f44 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 19 Sep 2017 11:30:37 +0500 Subject: Fix T52811: At any framerate selected, video exported with 1000fps --- source/blender/blenkernel/intern/writeffmpeg.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c index 156b74f5c3d..a19e4142894 100644 --- a/source/blender/blenkernel/intern/writeffmpeg.c +++ b/source/blender/blenkernel/intern/writeffmpeg.c @@ -681,6 +681,7 @@ static AVStream *alloc_video_stream(FFMpegContext *context, RenderData *rd, int /* xasp & yasp got float lately... */ st->sample_aspect_ratio = c->sample_aspect_ratio = av_d2q(((double) rd->xasp / (double) rd->yasp), 255); + st->avg_frame_rate = av_inv_q(c->time_base); set_ffmpeg_properties(rd, c, "video", &opts); -- cgit v1.2.3 From 215651af1b09571eaceafd1c4269d559eb5328ca Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 19 Sep 2017 18:29:52 +1000 Subject: Boolean Modifier: add debug options Only show & use when running in debug mode. --- source/blender/makesdna/DNA_modifier_types.h | 10 +++++++++- source/blender/makesrna/intern/rna_modifier.c | 17 +++++++++++++++++ source/blender/modifiers/intern/MOD_boolean.c | 9 ++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) (limited to 'source/blender') diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 67b29264d6c..e2dde412163 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -654,7 +654,8 @@ typedef struct BooleanModifierData { struct Object *object; char operation; char solver; - char pad[2]; + char pad; + char bm_flag; float double_threshold; } BooleanModifierData; @@ -669,6 +670,13 @@ typedef enum { eBooleanModifierSolver_BMesh = 1, } BooleanSolver; +/* bm_flag (only used when G_DEBUG) */ +enum { + eBooleanModifierBMeshFlag_BMesh_Separate = (1 << 0), + eBooleanModifierBMeshFlag_BMesh_NoDissolve = (1 << 1), + eBooleanModifierBMeshFlag_BMesh_NoConnectRegions = (1 << 2), +}; + typedef struct MDefInfluence { int vertex; float weight; diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index 96b88d98270..4db8b9e9de9 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -1977,6 +1977,23 @@ static void rna_def_modifier_boolean(BlenderRNA *brna) RNA_def_property_ui_range(prop, 0, 1, 0.0001, 6); RNA_def_property_ui_text(prop, "Overlap Threshold", "Threshold for checking overlapping geometry"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + /* BMesh debugging options, only used when G_DEBUG is set */ + + /* BMesh intersection options */ + static EnumPropertyItem debug_items[] = { + {eBooleanModifierBMeshFlag_BMesh_Separate, "SEPARATE", 0, "Separate", ""}, + {eBooleanModifierBMeshFlag_BMesh_NoDissolve, "NO_DISSOLVE", 0, "NoDissolve", ""}, + {eBooleanModifierBMeshFlag_BMesh_NoConnectRegions, "NO_CONNECT_REGIONS", 0, "NoConnectRegions", ""}, + {0, NULL, 0, NULL, NULL} + }; + + prop = RNA_def_property(srna, "debug_options", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, debug_items); + RNA_def_property_enum_sdna(prop, NULL, "bm_flag"); + RNA_def_property_flag(prop, PROP_ENUM_FLAG); + RNA_def_property_ui_text(prop, "Debug", "Debugging options, only when started with '-d'"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); } static void rna_def_modifier_array(BlenderRNA *brna) diff --git a/source/blender/modifiers/intern/MOD_boolean.c b/source/blender/modifiers/intern/MOD_boolean.c index f94ab777eb4..1140460161f 100644 --- a/source/blender/modifiers/intern/MOD_boolean.c +++ b/source/blender/modifiers/intern/MOD_boolean.c @@ -59,6 +59,7 @@ #include "BLI_alloca.h" #include "BLI_math_geom.h" #include "BKE_material.h" +#include "BKE_global.h" /* only to check G.debug */ #include "MEM_guardedalloc.h" #include "bmesh.h" @@ -322,11 +323,17 @@ static DerivedMesh *applyModifier_bmesh( * currently this is ok for 'BM_mesh_intersect' */ // BM_mesh_normals_update(bm); - /* change for testing */ bool use_separate = false; bool use_dissolve = true; bool use_island_connect = true; + /* change for testing */ + if (G.debug & G_DEBUG) { + use_separate = (bmd->bm_flag & eBooleanModifierBMeshFlag_BMesh_Separate) != 0; + use_dissolve = (bmd->bm_flag & eBooleanModifierBMeshFlag_BMesh_NoDissolve) == 0; + use_island_connect = (bmd->bm_flag & eBooleanModifierBMeshFlag_BMesh_NoConnectRegions) == 0; + } + BM_mesh_intersect( bm, looptris, tottri, -- cgit v1.2.3 From 60956397ca46ae31f5fc1931a8a7fc98d4f1b699 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 19 Sep 2017 20:16:05 +1000 Subject: Cleanup: BLI_utildefines prefix for header-only libs This allows to have different macro headers without them sharing similar names to regular C modules. --- source/blender/blenkernel/intern/cdderivedmesh.c | 2 +- source/blender/blenlib/BLI_stackdefines.h | 89 ---------------------- source/blender/blenlib/BLI_string_utils.h | 2 +- source/blender/blenlib/BLI_utildefines.h | 2 +- source/blender/blenlib/BLI_utildefines_stack.h | 89 ++++++++++++++++++++++ source/blender/blenlib/BLI_utildefines_variadic.h | 50 ++++++++++++ source/blender/blenlib/BLI_variadic_defines.h | 50 ------------ source/blender/bmesh/intern/bmesh_core.c | 2 +- .../blender/bmesh/intern/bmesh_polygon_edgenet.c | 2 +- source/blender/bmesh/intern/bmesh_queries.c | 2 +- source/blender/bmesh/operators/bmo_bisect_plane.c | 2 +- source/blender/bmesh/operators/bmo_connect.c | 2 +- .../blender/bmesh/operators/bmo_offset_edgeloops.c | 2 +- source/blender/bmesh/operators/bmo_removedoubles.c | 2 +- .../bmesh/operators/bmo_subdivide_edgering.c | 2 +- source/blender/bmesh/tools/bmesh_bisect_plane.c | 2 +- .../blender/bmesh/tools/bmesh_decimate_collapse.c | 2 +- source/blender/bmesh/tools/bmesh_intersect.c | 2 +- source/blender/bmesh/tools/bmesh_path_region.c | 2 +- source/blender/editors/object/object_vgroup.c | 2 +- source/blender/editors/transform/transform.c | 2 +- .../blender/modifiers/intern/MOD_laplaciandeform.c | 2 +- source/blender/modifiers/intern/MOD_solidify.c | 2 +- source/blender/python/generic/py_capi_utils.h | 2 +- 24 files changed, 159 insertions(+), 159 deletions(-) delete mode 100644 source/blender/blenlib/BLI_stackdefines.h create mode 100644 source/blender/blenlib/BLI_utildefines_stack.h create mode 100644 source/blender/blenlib/BLI_utildefines_variadic.h delete mode 100644 source/blender/blenlib/BLI_variadic_defines.h (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 16e9f3d6777..0d59357a168 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -37,7 +37,7 @@ #include "BLI_math.h" #include "BLI_edgehash.h" #include "BLI_utildefines.h" -#include "BLI_stackdefines.h" +#include "BLI_utildefines_stack.h" #include "BKE_pbvh.h" #include "BKE_cdderivedmesh.h" diff --git a/source/blender/blenlib/BLI_stackdefines.h b/source/blender/blenlib/BLI_stackdefines.h deleted file mode 100644 index 42b11eb9a2b..00000000000 --- a/source/blender/blenlib/BLI_stackdefines.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -#ifndef __BLI_STACKDEFINES_H__ -#define __BLI_STACKDEFINES_H__ - -/** \file BLI_stackdefines.h - * \ingroup bli - * - * Macro's for a simple array based stack - * \note Caller handles alloc & free). - */ - -/* only validate array-bounds in debug mode */ -#ifdef DEBUG -# define STACK_DECLARE(stack) unsigned int _##stack##_index, _##stack##_totalloc -# define STACK_INIT(stack, tot) ((void)stack, (void)((_##stack##_index) = 0), (void)((_##stack##_totalloc) = (tot))) -# define _STACK_SIZETEST(stack, off) (BLI_assert((_##stack##_index) + (off) <= _##stack##_totalloc)) -# define _STACK_SWAP_TOTALLOC(stack_a, stack_b) SWAP(unsigned int, _##stack_a##_totalloc, _##stack_b##_totalloc) -#else -# define STACK_DECLARE(stack) unsigned int _##stack##_index -# define STACK_INIT(stack, tot) ((void)stack, (void)((_##stack##_index) = 0), (void)(0 ? (tot) : 0)) -# define _STACK_SIZETEST(stack, off) (void)(stack), (void)(off) -# define _STACK_SWAP_TOTALLOC(stack_a, stack_b) (void)(stack_a), (void)(stack_b) -#endif -#define _STACK_BOUNDSTEST(stack, index) ((void)stack, BLI_assert((unsigned int)(index) < _##stack##_index)) - - -#define STACK_SIZE(stack) ((void)stack, (_##stack##_index)) -#define STACK_CLEAR(stack) {(void)stack; _##stack##_index = 0; } ((void)0) -/** add item to stack */ -#define STACK_PUSH(stack, val) ((void)stack, _STACK_SIZETEST(stack, 1), ((stack)[(_##stack##_index)++] = (val))) -#define STACK_PUSH_RET(stack) ((void)stack, _STACK_SIZETEST(stack, 1), ((stack)[(_##stack##_index)++])) -#define STACK_PUSH_RET_PTR(stack) ((void)stack, _STACK_SIZETEST(stack, 1), &((stack)[(_##stack##_index)++])) -/** take last item from stack */ -#define STACK_POP(stack) ((_##stack##_index) ? ((stack)[--(_##stack##_index)]) : NULL) -#define STACK_POP_PTR(stack) ((_##stack##_index) ? &((stack)[--(_##stack##_index)]) : NULL) -#define STACK_POP_DEFAULT(stack, r) ((_##stack##_index) ? ((stack)[--(_##stack##_index)]) : (r)) -/** look at last item (assumes non-empty stack) */ -#define STACK_PEEK(stack) (BLI_assert(_##stack##_index), ((stack)[_##stack##_index - 1])) -#define STACK_PEEK_PTR(stack) (BLI_assert(_##stack##_index), &((stack)[_##stack##_index - 1])) -/** remove any item from the stack, take care, re-orders */ -#define STACK_REMOVE(stack, i) \ - { \ - const unsigned int _i = i; \ - _STACK_BOUNDSTEST(stack, _i); \ - if (--_##stack##_index != _i) { \ - stack[_i] = stack[_##stack##_index]; \ - } \ - } ((void)0) -#define STACK_DISCARD(stack, n) \ - { \ - const unsigned int _n = n; \ - BLI_assert(_##stack##_index >= _n); \ - (void)stack; \ - _##stack##_index -= _n; \ - } ((void)0) -#ifdef __GNUC__ -#define STACK_SWAP(stack_a, stack_b) { \ - SWAP(typeof(stack_a), stack_a, stack_b); \ - SWAP(unsigned int, _##stack_a##_index, _##stack_b##_index); \ - _STACK_SWAP_TOTALLOC(stack_a, stack_b); \ - } ((void)0) -#else -#define STACK_SWAP(stack_a, stack_b) { \ - SWAP(void *, stack_a, stack_b); \ - SWAP(unsigned int, _##stack_a##_index, _##stack_b##_index); \ - _STACK_SWAP_TOTALLOC(stack_a, stack_b); \ - } ((void)0) -#endif - -#endif /* __BLI_STACKDEFINES_H__ */ diff --git a/source/blender/blenlib/BLI_string_utils.h b/source/blender/blenlib/BLI_string_utils.h index 63c1e0344ad..5701bce51ea 100644 --- a/source/blender/blenlib/BLI_string_utils.h +++ b/source/blender/blenlib/BLI_string_utils.h @@ -39,7 +39,7 @@ extern "C" { #endif #include "BLI_compiler_attrs.h" -#include "BLI_variadic_defines.h" +#include "BLI_utildefines_variadic.h" struct ListBase; diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index ae2f948a284..66c7f247f61 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -39,7 +39,7 @@ extern "C" { /* avoid many includes for now */ #include "BLI_sys_types.h" #include "BLI_compiler_compat.h" -#include "BLI_variadic_defines.h" +#include "BLI_utildefines_variadic.h" #ifndef NDEBUG /* for BLI_assert */ #include diff --git a/source/blender/blenlib/BLI_utildefines_stack.h b/source/blender/blenlib/BLI_utildefines_stack.h new file mode 100644 index 00000000000..15b0029e727 --- /dev/null +++ b/source/blender/blenlib/BLI_utildefines_stack.h @@ -0,0 +1,89 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __BLI_UTILDEFINES_STACK_H__ +#define __BLI_UTILDEFINES_STACK_H__ + +/** \file BLI_utildefines_stack.h + * \ingroup bli + * + * Macro's for a simple array based stack + * \note Caller handles alloc & free). + */ + +/* only validate array-bounds in debug mode */ +#ifdef DEBUG +# define STACK_DECLARE(stack) unsigned int _##stack##_index, _##stack##_totalloc +# define STACK_INIT(stack, tot) ((void)stack, (void)((_##stack##_index) = 0), (void)((_##stack##_totalloc) = (tot))) +# define _STACK_SIZETEST(stack, off) (BLI_assert((_##stack##_index) + (off) <= _##stack##_totalloc)) +# define _STACK_SWAP_TOTALLOC(stack_a, stack_b) SWAP(unsigned int, _##stack_a##_totalloc, _##stack_b##_totalloc) +#else +# define STACK_DECLARE(stack) unsigned int _##stack##_index +# define STACK_INIT(stack, tot) ((void)stack, (void)((_##stack##_index) = 0), (void)(0 ? (tot) : 0)) +# define _STACK_SIZETEST(stack, off) (void)(stack), (void)(off) +# define _STACK_SWAP_TOTALLOC(stack_a, stack_b) (void)(stack_a), (void)(stack_b) +#endif +#define _STACK_BOUNDSTEST(stack, index) ((void)stack, BLI_assert((unsigned int)(index) < _##stack##_index)) + + +#define STACK_SIZE(stack) ((void)stack, (_##stack##_index)) +#define STACK_CLEAR(stack) {(void)stack; _##stack##_index = 0; } ((void)0) +/** add item to stack */ +#define STACK_PUSH(stack, val) ((void)stack, _STACK_SIZETEST(stack, 1), ((stack)[(_##stack##_index)++] = (val))) +#define STACK_PUSH_RET(stack) ((void)stack, _STACK_SIZETEST(stack, 1), ((stack)[(_##stack##_index)++])) +#define STACK_PUSH_RET_PTR(stack) ((void)stack, _STACK_SIZETEST(stack, 1), &((stack)[(_##stack##_index)++])) +/** take last item from stack */ +#define STACK_POP(stack) ((_##stack##_index) ? ((stack)[--(_##stack##_index)]) : NULL) +#define STACK_POP_PTR(stack) ((_##stack##_index) ? &((stack)[--(_##stack##_index)]) : NULL) +#define STACK_POP_DEFAULT(stack, r) ((_##stack##_index) ? ((stack)[--(_##stack##_index)]) : (r)) +/** look at last item (assumes non-empty stack) */ +#define STACK_PEEK(stack) (BLI_assert(_##stack##_index), ((stack)[_##stack##_index - 1])) +#define STACK_PEEK_PTR(stack) (BLI_assert(_##stack##_index), &((stack)[_##stack##_index - 1])) +/** remove any item from the stack, take care, re-orders */ +#define STACK_REMOVE(stack, i) \ + { \ + const unsigned int _i = i; \ + _STACK_BOUNDSTEST(stack, _i); \ + if (--_##stack##_index != _i) { \ + stack[_i] = stack[_##stack##_index]; \ + } \ + } ((void)0) +#define STACK_DISCARD(stack, n) \ + { \ + const unsigned int _n = n; \ + BLI_assert(_##stack##_index >= _n); \ + (void)stack; \ + _##stack##_index -= _n; \ + } ((void)0) +#ifdef __GNUC__ +#define STACK_SWAP(stack_a, stack_b) { \ + SWAP(typeof(stack_a), stack_a, stack_b); \ + SWAP(unsigned int, _##stack_a##_index, _##stack_b##_index); \ + _STACK_SWAP_TOTALLOC(stack_a, stack_b); \ + } ((void)0) +#else +#define STACK_SWAP(stack_a, stack_b) { \ + SWAP(void *, stack_a, stack_b); \ + SWAP(unsigned int, _##stack_a##_index, _##stack_b##_index); \ + _STACK_SWAP_TOTALLOC(stack_a, stack_b); \ + } ((void)0) +#endif + +#endif /* __BLI_UTILDEFINES_STACK_H__ */ diff --git a/source/blender/blenlib/BLI_utildefines_variadic.h b/source/blender/blenlib/BLI_utildefines_variadic.h new file mode 100644 index 00000000000..7c15754fd83 --- /dev/null +++ b/source/blender/blenlib/BLI_utildefines_variadic.h @@ -0,0 +1,50 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __BLI_UTILDEFINES_VARIADIC_H__ +#define __BLI_UTILDEFINES_VARIADIC_H__ + +/** \file BLI_utildefines_variadic.h + * \ingroup bli + */ + +/* --- internal helpers --- */ +#define _VA_NARGS_GLUE(x, y) x y +#define _VA_NARGS_RETURN_COUNT(\ + _1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, _9_, _10_, _11_, _12_, _13_, _14_, _15_, _16_, \ + _17_, _18_, _19_, _20_, _21_, _22_, _23_, _24_, _25_, _26_, _27_, _28_, _29_, _30_, _31_, _32_, \ + _33_, _34_, _35_, _36_, _37_, _38_, _39_, _40_, _41_, _42_, _43_, _44_, _45_, _46_, _47_, _48_, \ + _49_, _50_, _51_, _52_, _53_, _54_, _55_, _56_, _57_, _58_, _59_, _60_, _61_, _62_, _63_, _64_, \ + count, ...) count +#define _VA_NARGS_EXPAND(args) _VA_NARGS_RETURN_COUNT args +#define _VA_NARGS_OVERLOAD_MACRO2(name, count) name##count +#define _VA_NARGS_OVERLOAD_MACRO1(name, count) _VA_NARGS_OVERLOAD_MACRO2(name, count) +#define _VA_NARGS_OVERLOAD_MACRO(name, count) _VA_NARGS_OVERLOAD_MACRO1(name, count) +/* --- expose for re-use --- */ +/* 64 args max */ +#define VA_NARGS_COUNT(...) _VA_NARGS_EXPAND((__VA_ARGS__, \ + 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, \ + 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, \ + 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, \ + 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)) +#define VA_NARGS_CALL_OVERLOAD(name, ...) \ + _VA_NARGS_GLUE(_VA_NARGS_OVERLOAD_MACRO(name, VA_NARGS_COUNT(__VA_ARGS__)), (__VA_ARGS__)) + +#endif /* __BLI_UTILDEFINES_VARIADIC_H__ */ diff --git a/source/blender/blenlib/BLI_variadic_defines.h b/source/blender/blenlib/BLI_variadic_defines.h deleted file mode 100644 index a2ff8ee09e7..00000000000 --- a/source/blender/blenlib/BLI_variadic_defines.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -#ifndef __BLI_VARIADIC_DEFINES_H__ -#define __BLI_VARIADIC_DEFINES_H__ - -/** \file BLI_variadic_defines.h - * \ingroup bli - */ - -/* --- internal helpers --- */ -#define _VA_NARGS_GLUE(x, y) x y -#define _VA_NARGS_RETURN_COUNT(\ - _1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, _9_, _10_, _11_, _12_, _13_, _14_, _15_, _16_, \ - _17_, _18_, _19_, _20_, _21_, _22_, _23_, _24_, _25_, _26_, _27_, _28_, _29_, _30_, _31_, _32_, \ - _33_, _34_, _35_, _36_, _37_, _38_, _39_, _40_, _41_, _42_, _43_, _44_, _45_, _46_, _47_, _48_, \ - _49_, _50_, _51_, _52_, _53_, _54_, _55_, _56_, _57_, _58_, _59_, _60_, _61_, _62_, _63_, _64_, \ - count, ...) count -#define _VA_NARGS_EXPAND(args) _VA_NARGS_RETURN_COUNT args -#define _VA_NARGS_OVERLOAD_MACRO2(name, count) name##count -#define _VA_NARGS_OVERLOAD_MACRO1(name, count) _VA_NARGS_OVERLOAD_MACRO2(name, count) -#define _VA_NARGS_OVERLOAD_MACRO(name, count) _VA_NARGS_OVERLOAD_MACRO1(name, count) -/* --- expose for re-use --- */ -/* 64 args max */ -#define VA_NARGS_COUNT(...) _VA_NARGS_EXPAND((__VA_ARGS__, \ - 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, \ - 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, \ - 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, \ - 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)) -#define VA_NARGS_CALL_OVERLOAD(name, ...) \ - _VA_NARGS_GLUE(_VA_NARGS_OVERLOAD_MACRO(name, VA_NARGS_COUNT(__VA_ARGS__)), (__VA_ARGS__)) - -#endif /* __BLI_VARIADIC_DEFINES_H__ */ diff --git a/source/blender/bmesh/intern/bmesh_core.c b/source/blender/bmesh/intern/bmesh_core.c index 6b22fd0a85c..c7ff93cf504 100644 --- a/source/blender/bmesh/intern/bmesh_core.c +++ b/source/blender/bmesh/intern/bmesh_core.c @@ -32,7 +32,7 @@ #include "BLI_array.h" #include "BLI_alloca.h" #include "BLI_linklist_stack.h" -#include "BLI_stackdefines.h" +#include "BLI_utildefines_stack.h" #include "BLT_translation.h" diff --git a/source/blender/bmesh/intern/bmesh_polygon_edgenet.c b/source/blender/bmesh/intern/bmesh_polygon_edgenet.c index 1b35f049838..8a3cb329610 100644 --- a/source/blender/bmesh/intern/bmesh_polygon_edgenet.c +++ b/source/blender/bmesh/intern/bmesh_polygon_edgenet.c @@ -32,7 +32,7 @@ #include "BLI_memarena.h" #include "BLI_array.h" #include "BLI_alloca.h" -#include "BLI_stackdefines.h" +#include "BLI_utildefines_stack.h" #include "BLI_linklist_stack.h" #include "BLI_sort.h" #include "BLI_sort_utils.h" diff --git a/source/blender/bmesh/intern/bmesh_queries.c b/source/blender/bmesh/intern/bmesh_queries.c index 88f45c06c20..5bdc3927e16 100644 --- a/source/blender/bmesh/intern/bmesh_queries.c +++ b/source/blender/bmesh/intern/bmesh_queries.c @@ -36,7 +36,7 @@ #include "BLI_math.h" #include "BLI_alloca.h" #include "BLI_linklist.h" -#include "BLI_stackdefines.h" +#include "BLI_utildefines_stack.h" #include "BKE_customdata.h" diff --git a/source/blender/bmesh/operators/bmo_bisect_plane.c b/source/blender/bmesh/operators/bmo_bisect_plane.c index 2c80ff651b8..ed232e81b82 100644 --- a/source/blender/bmesh/operators/bmo_bisect_plane.c +++ b/source/blender/bmesh/operators/bmo_bisect_plane.c @@ -29,7 +29,7 @@ #include "MEM_guardedalloc.h" #include "BLI_utildefines.h" -#include "BLI_stackdefines.h" +#include "BLI_utildefines_stack.h" #include "BLI_math.h" #include "bmesh.h" diff --git a/source/blender/bmesh/operators/bmo_connect.c b/source/blender/bmesh/operators/bmo_connect.c index c5c4ac959a9..0b5f1bb9ca1 100644 --- a/source/blender/bmesh/operators/bmo_connect.c +++ b/source/blender/bmesh/operators/bmo_connect.c @@ -27,7 +27,7 @@ */ #include "BLI_utildefines.h" -#include "BLI_stackdefines.h" +#include "BLI_utildefines_stack.h" #include "BLI_alloca.h" #include "BLI_linklist_stack.h" diff --git a/source/blender/bmesh/operators/bmo_offset_edgeloops.c b/source/blender/bmesh/operators/bmo_offset_edgeloops.c index a9840a72fc9..269f933f27f 100644 --- a/source/blender/bmesh/operators/bmo_offset_edgeloops.c +++ b/source/blender/bmesh/operators/bmo_offset_edgeloops.c @@ -33,7 +33,7 @@ #include "BLI_math.h" #include "BLI_alloca.h" -#include "BLI_stackdefines.h" +#include "BLI_utildefines_stack.h" #include "BKE_customdata.h" diff --git a/source/blender/bmesh/operators/bmo_removedoubles.c b/source/blender/bmesh/operators/bmo_removedoubles.c index d8e6f250adf..e85751531ae 100644 --- a/source/blender/bmesh/operators/bmo_removedoubles.c +++ b/source/blender/bmesh/operators/bmo_removedoubles.c @@ -31,7 +31,7 @@ #include "BLI_math.h" #include "BLI_alloca.h" #include "BLI_kdtree.h" -#include "BLI_stackdefines.h" +#include "BLI_utildefines_stack.h" #include "BLI_stack.h" #include "BKE_customdata.h" diff --git a/source/blender/bmesh/operators/bmo_subdivide_edgering.c b/source/blender/bmesh/operators/bmo_subdivide_edgering.c index 94b60a51f68..adcc0c71629 100644 --- a/source/blender/bmesh/operators/bmo_subdivide_edgering.c +++ b/source/blender/bmesh/operators/bmo_subdivide_edgering.c @@ -40,7 +40,7 @@ #include "MEM_guardedalloc.h" #include "BLI_utildefines.h" -#include "BLI_stackdefines.h" +#include "BLI_utildefines_stack.h" #include "BLI_alloca.h" #include "BLI_math.h" #include "BLI_listbase.h" diff --git a/source/blender/bmesh/tools/bmesh_bisect_plane.c b/source/blender/bmesh/tools/bmesh_bisect_plane.c index 676a8de94c8..f3927a3ff67 100644 --- a/source/blender/bmesh/tools/bmesh_bisect_plane.c +++ b/source/blender/bmesh/tools/bmesh_bisect_plane.c @@ -38,7 +38,7 @@ #include "MEM_guardedalloc.h" #include "BLI_utildefines.h" -#include "BLI_stackdefines.h" +#include "BLI_utildefines_stack.h" #include "BLI_alloca.h" #include "BLI_linklist.h" #include "BLI_linklist_stack.h" diff --git a/source/blender/bmesh/tools/bmesh_decimate_collapse.c b/source/blender/bmesh/tools/bmesh_decimate_collapse.c index c417131d588..36ae7231f94 100644 --- a/source/blender/bmesh/tools/bmesh_decimate_collapse.c +++ b/source/blender/bmesh/tools/bmesh_decimate_collapse.c @@ -40,7 +40,7 @@ #include "BLI_edgehash.h" #include "BLI_polyfill2d.h" #include "BLI_polyfill2d_beautify.h" -#include "BLI_stackdefines.h" +#include "BLI_utildefines_stack.h" #include "BKE_customdata.h" diff --git a/source/blender/bmesh/tools/bmesh_intersect.c b/source/blender/bmesh/tools/bmesh_intersect.c index b9408492cc1..9d1b20cb4d2 100644 --- a/source/blender/bmesh/tools/bmesh_intersect.c +++ b/source/blender/bmesh/tools/bmesh_intersect.c @@ -44,7 +44,7 @@ #include "BLI_sort_utils.h" #include "BLI_linklist_stack.h" -#include "BLI_stackdefines.h" +#include "BLI_utildefines_stack.h" #ifndef NDEBUG # include "BLI_array_utils.h" #endif diff --git a/source/blender/bmesh/tools/bmesh_path_region.c b/source/blender/bmesh/tools/bmesh_path_region.c index 27609ec3d48..d23ea537d82 100644 --- a/source/blender/bmesh/tools/bmesh_path_region.c +++ b/source/blender/bmesh/tools/bmesh_path_region.c @@ -29,7 +29,7 @@ #include "BLI_math.h" #include "BLI_linklist.h" -#include "BLI_stackdefines.h" +#include "BLI_utildefines_stack.h" #include "BLI_alloca.h" #include "bmesh.h" diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 19893c79db4..584176e4b5d 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -50,7 +50,7 @@ #include "BLI_blenlib.h" #include "BLI_utildefines.h" #include "BLI_linklist_stack.h" -#include "BLI_stackdefines.h" +#include "BLI_utildefines_stack.h" #include "BKE_context.h" diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 8cabf8d78ed..c2f04005e83 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -51,7 +51,7 @@ #include "BLI_listbase.h" #include "BLI_string.h" #include "BLI_ghash.h" -#include "BLI_stackdefines.h" +#include "BLI_utildefines_stack.h" #include "BLI_memarena.h" #include "BKE_nla.h" diff --git a/source/blender/modifiers/intern/MOD_laplaciandeform.c b/source/blender/modifiers/intern/MOD_laplaciandeform.c index 153670d327c..c2896e83a0b 100644 --- a/source/blender/modifiers/intern/MOD_laplaciandeform.c +++ b/source/blender/modifiers/intern/MOD_laplaciandeform.c @@ -29,7 +29,7 @@ */ #include "BLI_utildefines.h" -#include "BLI_stackdefines.h" +#include "BLI_utildefines_stack.h" #include "BLI_math.h" #include "BLI_string.h" diff --git a/source/blender/modifiers/intern/MOD_solidify.c b/source/blender/modifiers/intern/MOD_solidify.c index 911b6997058..e96771e0665 100644 --- a/source/blender/modifiers/intern/MOD_solidify.c +++ b/source/blender/modifiers/intern/MOD_solidify.c @@ -36,7 +36,7 @@ #include "MEM_guardedalloc.h" #include "BLI_utildefines.h" -#include "BLI_stackdefines.h" +#include "BLI_utildefines_stack.h" #include "BLI_bitmap.h" #include "BLI_math.h" diff --git a/source/blender/python/generic/py_capi_utils.h b/source/blender/python/generic/py_capi_utils.h index 053250a2a95..327d4e60954 100644 --- a/source/blender/python/generic/py_capi_utils.h +++ b/source/blender/python/generic/py_capi_utils.h @@ -28,7 +28,7 @@ #define __PY_CAPI_UTILS_H__ #include "BLI_sys_types.h" -#include "BLI_variadic_defines.h" +#include "BLI_utildefines_variadic.h" void PyC_ObSpit(const char *name, PyObject *var); void PyC_LineSpit(void); -- cgit v1.2.3 From 7b952432409a6d1f268699846cbbf6fc00c347c7 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 19 Sep 2017 20:21:52 +1000 Subject: BLI_utildefines_iter: Use for iteration helpers --- source/blender/blenlib/BLI_utildefines_iter.h | 52 +++++++++++++++++++++++++++ source/blender/bmesh/intern/bmesh_edgeloop.c | 24 +------------ 2 files changed, 53 insertions(+), 23 deletions(-) create mode 100644 source/blender/blenlib/BLI_utildefines_iter.h (limited to 'source/blender') diff --git a/source/blender/blenlib/BLI_utildefines_iter.h b/source/blender/blenlib/BLI_utildefines_iter.h new file mode 100644 index 00000000000..094c1a4b3dc --- /dev/null +++ b/source/blender/blenlib/BLI_utildefines_iter.h @@ -0,0 +1,52 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __BLI_UTILDEFINES_ITER_H__ +#define __BLI_UTILDEFINES_ITER_H__ + +/** \file BLI_utildefines_iter.h + * \ingroup bli + * + * General looping helpers, use `BLI_FOREACH` prefix. + */ + +/** + * Even value distribution. + * + * \a src must be larger than \a dst, + * \a dst defines the number of iterations, their values are evenly spaced. + * + * The following pairs represent (src, dst) arguments and the values they loop over. + *
+ * (19, 4) ->    [2, 7, 11. 16]
+ * (100, 5) ->   [9, 29, 49, 69, 89]
+ * (100, 3) ->   [16, 49, 83]
+ * (100, 100) -> [0..99]
+ * 
+ * \note this is mainly useful for numbers that might not divide evenly into eachother. + */ +#define BLI_FOREACH_SPARSE_RANGE(src, dst, i) \ +for (int _src = (src), _src2 = _src * 2, _dst2 = (dst) * 2, _error = _dst2 - _src, i = 0, _delta; \ + ((void)(_delta = divide_floor_i(_error, _dst2)), \ + (void)(i -= _delta), \ + (i < _src)); \ + _error -= (_delta * _dst2) + _src2) + +#endif /* __BLI_UTILDEFINES_ITER_H__ */ diff --git a/source/blender/bmesh/intern/bmesh_edgeloop.c b/source/blender/bmesh/intern/bmesh_edgeloop.c index 97840df3a5d..b3b23933d2f 100644 --- a/source/blender/bmesh/intern/bmesh_edgeloop.c +++ b/source/blender/bmesh/intern/bmesh_edgeloop.c @@ -32,6 +32,7 @@ #include "BLI_math_vector.h" #include "BLI_listbase.h" #include "BLI_mempool.h" +#include "BLI_utildefines_iter.h" #include "bmesh.h" @@ -707,29 +708,6 @@ void BM_edgeloop_expand( split_swap = !split_swap; } - /* TODO, move to generic define? */ - /** - * Even value distribution. - * - * \a src must be larger than \a dst, - * \a dst defines the number of iterations, their values are evenly spaced. - * - * The following pairs represent (src, dst) arguments and the values they loop over. - *
-	 * (19, 4) ->    [2, 7, 11. 16]
-	 * (100, 5) ->   [9, 29, 49, 69, 89]
-	 * (100, 3) ->   [16, 49, 83]
-	 * (100, 100) -> [0..99]
-	 * 
- * \note this is mainly useful for numbers that might not divide evenly into eachother. - */ -#define BLI_FOREACH_SPARSE_RANGE(src, dst, i) \ - for (int _src = (src), _src2 = _src * 2, _dst2 = (dst) * 2, _error = _dst2 - _src, i = 0, _delta; \ - ((void)(_delta = divide_floor_i(_error, _dst2)), \ - (void)(i -= _delta), \ - (i < _src)); \ - _error -= (_delta * _dst2) + _src2) - if (el_store->len < el_store_len) { LinkData *node_curr = el_store->verts.first; -- cgit v1.2.3 From 495d3c8dd75421be2f3f5c5b31690eaedacf6e4e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 19 Sep 2017 20:25:20 +1000 Subject: CMake: update for renamed headers --- source/blender/blenlib/CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index f42848eec8f..61a1241cd8f 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -192,7 +192,6 @@ set(SRC BLI_sort.h BLI_sort_utils.h BLI_stack.h - BLI_stackdefines.h BLI_strict_flags.h BLI_string.h BLI_string_cursor_utf8.h @@ -204,8 +203,10 @@ set(SRC BLI_threads.h BLI_timecode.h BLI_utildefines.h + BLI_utildefines_iter.h + BLI_utildefines_stack.h + BLI_utildefines_variadic.h BLI_uvproject.h - BLI_variadic_defines.h BLI_vfontdata.h BLI_voronoi.h BLI_voxel.h -- cgit v1.2.3 From 1a4442b3dbadd685b9c6a70fa9694748b2a6e2d3 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 19 Sep 2017 16:09:35 +0500 Subject: Fix T52823: New Depsgraph - Shrinkwrap crashes blender The issue was caused by threading conflict around looptris: it was possible that DM will return non-NULL but non-initialized array of looptris. Thanks Campbell for second pair of eyes! --- source/blender/blenkernel/intern/DerivedMesh.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index e53f14291b7..12d0c68f4d8 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -94,7 +94,7 @@ static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm); #endif -static ThreadMutex loops_cache_lock = BLI_MUTEX_INITIALIZER; +static ThreadRWMutex loops_cache_lock = PTHREAD_RWLOCK_INITIALIZER; static void add_shapekey_layers(DerivedMesh *dm, Mesh *me, Object *ob); @@ -241,19 +241,26 @@ static int dm_getNumLoopTri(DerivedMesh *dm) static const MLoopTri *dm_getLoopTriArray(DerivedMesh *dm) { - if (dm->looptris.array) { + MLoopTri *looptri; + + BLI_rw_mutex_lock(&loops_cache_lock, THREAD_LOCK_READ); + looptri = dm->looptris.array; + BLI_rw_mutex_unlock(&loops_cache_lock); + + if (looptri != NULL) { BLI_assert(dm->getNumLoopTri(dm) == dm->looptris.num); } else { - BLI_mutex_lock(&loops_cache_lock); + BLI_rw_mutex_lock(&loops_cache_lock, THREAD_LOCK_WRITE); /* We need to ensure array is still NULL inside mutex-protected code, some other thread might have already * recomputed those looptris. */ if (dm->looptris.array == NULL) { dm->recalcLoopTri(dm); } - BLI_mutex_unlock(&loops_cache_lock); + looptri = dm->looptris.array; + BLI_rw_mutex_unlock(&loops_cache_lock); } - return dm->looptris.array; + return looptri; } static CustomData *dm_getVertCData(DerivedMesh *dm) -- cgit v1.2.3 From 9591b5f6182f754dc06e1aff43d6b8b675aa9bf4 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Tue, 19 Sep 2017 13:57:46 +0200 Subject: Fix T52816: regression can't open file in 2.79 (crash). Tentative fix, since I cannot reproduce thenissue for some reason here on linux. Core of the problem is pretty clear though, thanks to Germano Cavalcante (@mano-wii): another thread could try to use looptris data after worker one had allocated it, but before it had actually computed looptris. So now, we use a temp 'wip' pointer to store looptris being computed (since this is protected by a mutex, other threads will have to wait on it, no possibility for them to double-compute the looptris here). This should probably be backported to 2.79a if done. --- source/blender/blenkernel/BKE_DerivedMesh.h | 4 +++- source/blender/blenkernel/intern/DerivedMesh.c | 12 +++++++++--- source/blender/blenkernel/intern/cdderivedmesh.c | 6 +++++- source/blender/blenkernel/intern/editderivedmesh.c | 6 +++++- source/blender/blenkernel/intern/subsurf_ccg.c | 6 +++++- 5 files changed, 27 insertions(+), 7 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index e2577689101..700bfe568f1 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -193,7 +193,9 @@ struct DerivedMesh { * \warning Typical access is done via #getLoopTriArray, #getNumLoopTri. */ struct { - struct MLoopTri *array; + /* WARNING! swapping between array (ready-to-be-used data) and array_wip (where data is actually computed) + * shall always be protected by same lock as one used for looptris computing. */ + struct MLoopTri *array, *array_wip; int num; int num_alloc; } looptris; diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 12d0c68f4d8..ace79f4125b 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -501,6 +501,8 @@ void DM_ensure_tessface(DerivedMesh *dm) /** * Ensure the array is large enough + * + * /note This function must always be thread-protected by caller. It should only be used by internal code. */ void DM_ensure_looptri_data(DerivedMesh *dm) { @@ -508,18 +510,22 @@ void DM_ensure_looptri_data(DerivedMesh *dm) const unsigned int totloop = dm->numLoopData; const int looptris_num = poly_to_tri_count(totpoly, totloop); + BLI_assert(dm->looptris.array_wip == NULL); + + SWAP(MLoopTri *, dm->looptris.array, dm->looptris.array_wip); + if ((looptris_num > dm->looptris.num_alloc) || (looptris_num < dm->looptris.num_alloc * 2) || (totpoly == 0)) { - MEM_SAFE_FREE(dm->looptris.array); + MEM_SAFE_FREE(dm->looptris.array_wip); dm->looptris.num_alloc = 0; dm->looptris.num = 0; } if (totpoly) { - if (dm->looptris.array == NULL) { - dm->looptris.array = MEM_mallocN(sizeof(*dm->looptris.array) * looptris_num, __func__); + if (dm->looptris.array_wip == NULL) { + dm->looptris.array_wip = MEM_mallocN(sizeof(*dm->looptris.array_wip) * looptris_num, __func__); dm->looptris.num_alloc = looptris_num; } diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 0d59357a168..47e1f0beb31 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -1919,12 +1919,16 @@ void CDDM_recalc_looptri(DerivedMesh *dm) const unsigned int totloop = dm->numLoopData; DM_ensure_looptri_data(dm); + BLI_assert(cddm->dm.looptris.array_wip != NULL); BKE_mesh_recalc_looptri( cddm->mloop, cddm->mpoly, cddm->mvert, totloop, totpoly, - cddm->dm.looptris.array); + cddm->dm.looptris.array_wip); + + BLI_assert(cddm->dm.looptris.array == NULL); + SWAP(MLoopTri *, cddm->dm.looptris.array, cddm->dm.looptris.array_wip); } static void cdDM_free_internal(CDDerivedMesh *cddm) diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c index f29af28a782..ae4d567edf4 100644 --- a/source/blender/blenkernel/intern/editderivedmesh.c +++ b/source/blender/blenkernel/intern/editderivedmesh.c @@ -641,8 +641,9 @@ static void emDM_recalcLoopTri(DerivedMesh *dm) int i; DM_ensure_looptri_data(dm); - mlooptri = dm->looptris.array; + mlooptri = dm->looptris.array_wip; + BLI_assert(mlooptri != NULL); BLI_assert(poly_to_tri_count(dm->numPolyData, dm->numLoopData) == dm->looptris.num); BLI_assert(tottri == dm->looptris.num); @@ -659,6 +660,9 @@ static void emDM_recalcLoopTri(DerivedMesh *dm) BM_elem_index_get(ltri[2])); lt->poly = BM_elem_index_get(ltri[0]->f); } + + BLI_assert(dm->looptris.array == NULL); + SWAP(MLoopTri *, dm->looptris.array, dm->looptris.array_wip); } static void emDM_foreachMappedVert( diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index ff0682258c6..ee1f5dc6696 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -4482,8 +4482,9 @@ static void ccgDM_recalcLoopTri(DerivedMesh *dm) int i, poly_index; DM_ensure_looptri_data(dm); - mlooptri = dm->looptris.array; + mlooptri = dm->looptris.array_wip; + BLI_assert(mlooptri != NULL); BLI_assert(poly_to_tri_count(dm->numPolyData, dm->numLoopData) == dm->looptris.num); BLI_assert(tottri == dm->looptris.num); @@ -4502,6 +4503,9 @@ static void ccgDM_recalcLoopTri(DerivedMesh *dm) lt->tri[2] = (poly_index * 4) + 2; lt->poly = poly_index; } + + BLI_assert(dm->looptris.array == NULL); + SWAP(MLoopTri *, dm->looptris.array, dm->looptris.array_wip); } static void ccgDM_calcNormals(DerivedMesh *dm) -- cgit v1.2.3 From 96ce50449c3060514e28d79d7e488d0d2b16354e Mon Sep 17 00:00:00 2001 From: Howard Trickey Date: Tue, 19 Sep 2017 09:38:17 -0400 Subject: Fix T52733 Percent mode for Bevel sometimes had nans. Forgot some initialization. --- source/blender/editors/mesh/editmesh_bevel.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/editors/mesh/editmesh_bevel.c b/source/blender/editors/mesh/editmesh_bevel.c index a81add7a86e..6b4f3516338 100644 --- a/source/blender/editors/mesh/editmesh_bevel.c +++ b/source/blender/editors/mesh/editmesh_bevel.c @@ -150,6 +150,7 @@ static bool edbm_bevel_init(bContext *C, wmOperator *op, const bool is_modal) for (i = 0; i < NUM_VALUE_KINDS; i++) { opdata->shift_value[i] = -1.0f; + opdata->initial_length[i] = -1.0f; /* note: scale for OFFSET_VALUE will get overwritten in edbm_bevel_invoke */ opdata->scale[i] = value_scale_per_inch[i] / pixels_per_inch; @@ -300,7 +301,7 @@ static void edbm_bevel_calc_initial_length(wmOperator *op, const wmEvent *event, mlen[1] = opdata->mcenter[1] - event->mval[1]; len = len_v2(mlen); vmode = opdata->value_mode; - if (mode_changed) { + if (mode_changed || opdata->initial_length[vmode] == -1.0f) { /* If current value is not default start value, adjust len so that * the scaling and offset in edbm_bevel_mouse_set_value will * start at current value */ @@ -506,6 +507,8 @@ static int edbm_bevel_modal(bContext *C, wmOperator *op, const wmEvent *event) else if (opdata->value_mode == OFFSET_VALUE_PERCENT && type != BEVEL_AMT_PERCENT) opdata->value_mode = OFFSET_VALUE; RNA_property_enum_set(op->ptr, prop, type); + if (opdata->initial_length[opdata->value_mode] == -1.0f) + edbm_bevel_calc_initial_length(op, event, true); } /* Update offset accordingly to new offset_type. */ if (!has_numinput && -- cgit v1.2.3 From b31faac17eaf66e034107f136bb00dd16361a0bf Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 19 Sep 2017 20:55:15 +0500 Subject: Depsgraph: Fix wrong flag being assigned --- source/blender/depsgraph/intern/eval/deg_eval_flush.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source/blender') diff --git a/source/blender/depsgraph/intern/eval/deg_eval_flush.cc b/source/blender/depsgraph/intern/eval/deg_eval_flush.cc index 40f6901de33..0adbadeebba 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval_flush.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval_flush.cc @@ -210,8 +210,8 @@ void deg_graph_flush_updates(Main *bmain, Depsgraph *graph) } } - id_node->done = COMPONENT_STATE_DONE; - comp_node->done = 1; + id_node->done = 1; + comp_node->done = COMPONENT_STATE_DONE; /* Flush to nodes along links... */ /* TODO(sergey): This is mainly giving speedup due ot less queue pushes, which -- cgit v1.2.3