From b0015686e2e48a384a0b2a03a75f6daaad7271c0 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 26 May 2017 15:21:15 +0200 Subject: Fix T50908: Motion Tracker ignored grease pencil mask This feature got lost with new auto-track API, Added it back by extending frame accessor class. This isn't really a frame thing, but we don't have other type of accessor here. Surely, we can use old-style API here and pass mask via region tracker options for this particular case, but then it becomes much less obvious how real auto-tracker will access this mask with old style API. So seems we do need an accessor for such data, just matter of finding better place than frame accessor. --- source/blender/blenkernel/intern/tracking.c | 51 +++++++++++++------ source/blender/blenkernel/intern/tracking_auto.c | 17 ++++++- source/blender/blenkernel/intern/tracking_util.c | 62 +++++++++++++++++++++++- source/blender/blenkernel/tracking_private.h | 11 +++++ 4 files changed, 122 insertions(+), 19 deletions(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index 990d250b854..bfe8dcbb21e 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -974,8 +974,11 @@ static void track_mask_set_pixel_cb(int x, int x_end, int y, void *user_data) } static void track_mask_gpencil_layer_rasterize(int frame_width, int frame_height, - MovieTrackingMarker *marker, bGPDlayer *layer, - float *mask, int mask_width, int mask_height) + const float region_min[2], + bGPDlayer *layer, + float *mask, + int mask_width, + int mask_height) { bGPDframe *frame = layer->frames.first; TrackMaskSetPixelData data; @@ -994,8 +997,8 @@ static void track_mask_gpencil_layer_rasterize(int frame_width, int frame_height point = mask_points = MEM_callocN(2 * stroke->totpoints * sizeof(int), "track mask rasterization points"); for (int i = 0; i < stroke->totpoints; i++, point += 2) { - point[0] = (stroke_points[i].x - marker->search_min[0]) * frame_width; - point[1] = (stroke_points[i].y - marker->search_min[1]) * frame_height; + point[0] = stroke_points[i].x * frame_width - region_min[0]; + point[1] = stroke_points[i].y * frame_height - region_min[1]; } /* TODO: add an option to control whether AA is enabled or not */ BLI_bitmap_draw_2d_poly_v2i_n( @@ -1010,26 +1013,42 @@ static void track_mask_gpencil_layer_rasterize(int frame_width, int frame_height } } -float *BKE_tracking_track_get_mask(int frame_width, int frame_height, - MovieTrackingTrack *track, MovieTrackingMarker *marker) +/* Region is in pixel space, relative to marker's center. */ +float *tracking_track_get_mask_for_region(int frame_width, int frame_height, + const float region_min[2], + const float region_max[2], + MovieTrackingTrack *track) { float *mask = NULL; bGPDlayer *layer = track_mask_gpencil_layer_get(track); - int mask_width, mask_height; - - mask_width = (marker->search_max[0] - marker->search_min[0]) * frame_width; - mask_height = (marker->search_max[1] - marker->search_min[1]) * frame_height; - - if (layer) { + if (layer != NULL) { + const int mask_width = region_max[0] - region_min[0]; + const int mask_height = region_max[1] - region_min[1]; mask = MEM_callocN(mask_width * mask_height * sizeof(float), "track mask"); - - track_mask_gpencil_layer_rasterize(frame_width, frame_height, marker, layer, - mask, mask_width, mask_height); + track_mask_gpencil_layer_rasterize(frame_width, frame_height, + region_min, + layer, + mask, + mask_width, mask_height); } - return mask; } +float *BKE_tracking_track_get_mask(int frame_width, int frame_height, + MovieTrackingTrack *track, + MovieTrackingMarker *marker) +{ + /* Convert normalized space marker's search area to pixel-space region. */ + const float region_min[2] = {marker->search_min[0] * frame_width, + marker->search_min[1] * frame_height}; + const float region_max[2] = {marker->search_max[0] * frame_width, + marker->search_max[1] * frame_height}; + return tracking_track_get_mask_for_region(frame_width, frame_height, + region_min, + region_max, + track); +} + float BKE_tracking_track_get_weight_for_marker(MovieClip *clip, MovieTrackingTrack *track, MovieTrackingMarker *marker) { FCurve *weight_fcurve; diff --git a/source/blender/blenkernel/intern/tracking_auto.c b/source/blender/blenkernel/intern/tracking_auto.c index 3b56ea271d0..9475925cdda 100644 --- a/source/blender/blenkernel/intern/tracking_auto.c +++ b/source/blender/blenkernel/intern/tracking_auto.c @@ -36,8 +36,9 @@ #include "DNA_movieclip_types.h" #include "DNA_object_types.h" /* SELECT */ -#include "BLI_threads.h" #include "BLI_utildefines.h" +#include "BLI_listbase.h" +#include "BLI_threads.h" #include "BLI_math.h" #include "BKE_movieclip.h" @@ -76,6 +77,9 @@ typedef struct AutoTrackContext { int num_tracks; /* Number of tracks being tracked. */ AutoTrackOptions *options; /* Per-tracking track options. */ + /* Array of all tracks, indexed by track_index. */ + MovieTrackingTrack **tracks; + bool backwards; bool sequence; int first_frame; @@ -306,8 +310,15 @@ AutoTrackContext *BKE_autotrack_context_new(MovieClip *clip, BLI_spin_init(&context->spin_lock); + int num_total_tracks = BLI_listbase_count(tracksbase); + context->tracks = + MEM_callocN(sizeof(MovieTrackingTrack*) * num_total_tracks, + "auto track pointers"); + context->image_accessor = - tracking_image_accessor_new(context->clips, 1, user->framenr); + tracking_image_accessor_new(context->clips, 1, + context->tracks, num_total_tracks, + user->framenr); context->autotrack = libmv_autoTrackNew(context->image_accessor->libmv_accessor); @@ -361,6 +372,7 @@ AutoTrackContext *BKE_autotrack_context_new(MovieClip *clip, options->use_keyframe_match = track->pattern_match == TRACK_MATCH_KEYFRAME; } + context->tracks[track_index] = track; ++track_index; } @@ -565,6 +577,7 @@ void BKE_autotrack_context_free(AutoTrackContext *context) libmv_autoTrackDestroy(context->autotrack); tracking_image_accessor_destroy(context->image_accessor); MEM_freeN(context->options); + MEM_freeN(context->tracks); BLI_spin_end(&context->spin_lock); MEM_freeN(context); } diff --git a/source/blender/blenkernel/intern/tracking_util.c b/source/blender/blenkernel/intern/tracking_util.c index 1c056cda68d..a95399562d5 100644 --- a/source/blender/blenkernel/intern/tracking_util.c +++ b/source/blender/blenkernel/intern/tracking_util.c @@ -875,8 +875,64 @@ static void accessor_release_image_callback(libmv_CacheKey cache_key) IMB_freeImBuf(ibuf); } +static libmv_CacheKey accessor_get_mask_for_track_callback( + libmv_FrameAccessorUserData* user_data, + int clip_index, + int frame, + int track_index, + const libmv_Region *region, + float **r_destination, + int *r_width, + int *r_height) +{ + /* Perform sanity checks first. */ + TrackingImageAccessor *accessor = (TrackingImageAccessor *) user_data; + BLI_assert(clip_index < accessor->num_clips); + BLI_assert(track_index < accessor->num_tracks); + MovieTrackingTrack *track = accessor->tracks[track_index]; + /* Early output, track does not use mask. */ + if ((track->algorithm_flag & TRACK_ALGORITHM_FLAG_USE_MASK) == 0) { + return NULL; + } + MovieClip *clip = accessor->clips[clip_index]; + /* Construct fake user so we can access movie clip. */ + MovieClipUser user; + int scene_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, frame); + BKE_movieclip_user_set_frame(&user, scene_frame); + user.render_size = MCLIP_PROXY_RENDER_SIZE_FULL; + user.render_flag = 0; + /* Get frame width and height so we can convert stroke coordinates + * and other things from normalized to pixel space. + */ + int frame_width, frame_height; + BKE_movieclip_get_size(clip, &user, &frame_width, &frame_height); + /* Actual mask sampling. */ + MovieTrackingMarker *marker = BKE_tracking_marker_get_exact(track, frame); + const float region_min[2] = {region->min[0] - marker->pos[0] * frame_width, + region->min[1] - marker->pos[1] * frame_height}; + const float region_max[2] = {region->max[0] - marker->pos[0] * frame_width, + region->max[1] - marker->pos[1] * frame_height}; + *r_destination = tracking_track_get_mask_for_region(frame_width, frame_height, + region_min, + region_max, + track); + *r_width = region->max[0] - region->min[0]; + *r_height = region->max[1] - region->min[1]; + return *r_destination; +} + +static void accessor_release_mask_callback(libmv_CacheKey cache_key) +{ + if (cache_key != NULL) { + float *mask = (float *)cache_key; + MEM_freeN(mask); + } +} + TrackingImageAccessor *tracking_image_accessor_new(MovieClip *clips[MAX_ACCESSOR_CLIP], int num_clips, + MovieTrackingTrack **tracks, + int num_tracks, int start_frame) { TrackingImageAccessor *accessor = @@ -891,12 +947,16 @@ TrackingImageAccessor *tracking_image_accessor_new(MovieClip *clips[MAX_ACCESSOR memcpy(accessor->clips, clips, num_clips * sizeof(MovieClip *)); accessor->num_clips = num_clips; + accessor->tracks = tracks; + accessor->num_tracks = num_tracks; accessor->start_frame = start_frame; accessor->libmv_accessor = libmv_FrameAccessorNew((libmv_FrameAccessorUserData *) accessor, accessor_get_image_callback, - accessor_release_image_callback); + accessor_release_image_callback, + accessor_get_mask_for_track_callback, + accessor_release_mask_callback); return accessor; } diff --git a/source/blender/blenkernel/tracking_private.h b/source/blender/blenkernel/tracking_private.h index 591ee4d0d01..1a68a1cac6a 100644 --- a/source/blender/blenkernel/tracking_private.h +++ b/source/blender/blenkernel/tracking_private.h @@ -105,6 +105,13 @@ struct MovieTrackingMarker *tracking_get_keyframed_marker( int current_frame, bool backwards); +/*********************** Masking *************************/ + +float *tracking_track_get_mask_for_region(int frame_width, int frame_height, + const float region_min[2], + const float region_max[2], + MovieTrackingTrack *track); + /*********************** Frame accessr *************************/ struct libmv_FrameAccessor; @@ -114,12 +121,16 @@ typedef struct TrackingImageAccessor { struct MovieCache *cache; struct MovieClip *clips[MAX_ACCESSOR_CLIP]; int num_clips; + struct MovieTrackingTrack **tracks; + int num_tracks; int start_frame; struct libmv_FrameAccessor *libmv_accessor; } TrackingImageAccessor; TrackingImageAccessor *tracking_image_accessor_new(MovieClip *clips[MAX_ACCESSOR_CLIP], int num_clips, + MovieTrackingTrack **tracks, + int num_tracks, int start_frame); void tracking_image_accessor_destroy(TrackingImageAccessor *accessor); -- cgit v1.2.3 From 4d58080e235b8cde0c9a70542328135415b207b5 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Fri, 26 May 2017 21:48:18 +0200 Subject: Fix T50851: Array modifier generating invalid geometry. We had handling of fully duplicated polygons already, but... absolutely nothing to sanitize partially merged polygons! This were giving us totally invalid geometry, with duplicated vertices in single poly, invalid edges, etc. Now we do check for invalid loops inside polys, and generate new edges as needed to get only valid polys. For some reason this was a nightmare to get running fully OK, playing with old and new indices is really, really mind breaking. --- source/blender/blenkernel/intern/cdderivedmesh.c | 254 +++++++++++++++-------- source/blender/blenkernel/intern/mesh_validate.c | 4 +- 2 files changed, 173 insertions(+), 85 deletions(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 7042b46330b..3295cc69262 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -2992,9 +2992,12 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap, const int STACK_DECLARE(mvert); STACK_DECLARE(oldv); - MEdge *med, *medge = MEM_mallocN(sizeof(*medge) * totedge, __func__); - int *olde = MEM_mallocN(sizeof(*olde) * totedge, __func__); - int *newe = MEM_mallocN(sizeof(*newe) * totedge, __func__); + /* Note: create (totedge + totloop) elements because partially invalid polys due to merge may require + * generating new edges, and while in 99% cases we'll still end with less final edges than totedge, + * cases can be forged that would end requiring more... */ + MEdge *med, *medge = MEM_mallocN(sizeof(*medge) * (totedge + totloop), __func__); + int *olde = MEM_mallocN(sizeof(*olde) * (totedge + totloop), __func__); + int *newe = MEM_mallocN(sizeof(*newe) * (totedge + totloop), __func__); STACK_DECLARE(medge); STACK_DECLARE(olde); @@ -3028,7 +3031,7 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap, const int STACK_INIT(mloop, totloop); STACK_INIT(mpoly, totpoly); - /* fill newl with destination vertex indices */ + /* fill newv with destination vertex indices */ mv = cddm->mvert; c = 0; for (i = 0; i < totvert; i++, mv++) { @@ -3117,83 +3120,80 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap, const int mp = cddm->mpoly; + mv = cddm->mvert; for (i = 0; i < totpoly; i++, mp++) { MPoly *mp_new; ml = cddm->mloop + mp->loopstart; /* check faces with all vertices merged */ - { - bool all_vertices_merged = true; + bool all_vertices_merged = true; - for (j = 0; j < mp->totloop; j++, ml++) { - if (vtargetmap[ml->v] == -1) { - all_vertices_merged = false; - break; - } + for (j = 0; j < mp->totloop; j++, ml++) { + if (vtargetmap[ml->v] == -1) { + all_vertices_merged = false; + /* This will be used to check for poly using several time the same vert. */ + mv[ml->v].flag &= ~ME_VERT_TMP_TAG; } + else { + /* This will be used to check for poly using several time the same vert. */ + mv[vtargetmap[ml->v]].flag &= ~ME_VERT_TMP_TAG; + } + } - if (UNLIKELY(all_vertices_merged)) { - if (merge_mode == CDDM_MERGE_VERTS_DUMP_IF_MAPPED) { - /* In this mode, all vertices merged is enough to dump face */ - continue; + if (UNLIKELY(all_vertices_merged)) { + if (merge_mode == CDDM_MERGE_VERTS_DUMP_IF_MAPPED) { + /* In this mode, all vertices merged is enough to dump face */ + continue; + } + else if (merge_mode == CDDM_MERGE_VERTS_DUMP_IF_EQUAL) { + /* Additional condition for face dump: target vertices must make up an identical face */ + /* The test has 2 steps: (1) first step is fast ghash lookup, but not failproof */ + /* (2) second step is thorough but more costly poly compare */ + int i_poly, v_target; + bool found = false; + PolyKey pkey; + + /* Use poly_gset for fast (although not 100% certain) identification of same poly */ + /* First, make up a poly_summary structure */ + ml = cddm->mloop + mp->loopstart; + pkey.hash_sum = pkey.hash_xor = 0; + pkey.totloops = 0; + for (j = 0; j < mp->totloop; j++, ml++) { + v_target = vtargetmap[ml->v]; /* Cannot be -1, they are all mapped */ + pkey.hash_sum += v_target; + pkey.hash_xor ^= v_target; + pkey.totloops++; } - else if (merge_mode == CDDM_MERGE_VERTS_DUMP_IF_EQUAL) { - /* Additional condition for face dump: target vertices must make up an identical face */ - /* The test has 2 steps: (1) first step is fast ghash lookup, but not failproof */ - /* (2) second step is thorough but more costly poly compare */ - int i_poly, v_target, v_prev; - bool found = false; - PolyKey pkey; - - /* Use poly_gset for fast (although not 100% certain) identification of same poly */ - /* First, make up a poly_summary structure */ + if (BLI_gset_haskey(poly_gset, &pkey)) { + + /* There might be a poly that matches this one. + * We could just leave it there and say there is, and do a "continue". + * ... but we are checking whether there is an exact poly match. + * It's not so costly in terms of CPU since it's very rare, just a lot of complex code. + */ + + /* Consider current loop again */ ml = cddm->mloop + mp->loopstart; - pkey.hash_sum = pkey.hash_xor = 0; - pkey.totloops = 0; - v_prev = vtargetmap[(ml + mp->totloop -1)->v]; /* since it loops around, the prev of first is the last */ - for (j = 0; j < mp->totloop; j++, ml++) { - v_target = vtargetmap[ml->v]; /* Cannot be -1, they are all mapped */ - if (v_target == v_prev) { - /* consecutive vertices in loop map to the same target: discard */ - /* but what about last to first ? */ - continue; + /* Consider the target of the loop's first vert */ + v_target = vtargetmap[ml->v]; + /* Now see if v_target belongs to a poly that shares all vertices with source poly, + * in same order, or reverse order */ + + for (i_poly = 0; i_poly < cddm->pmap[v_target].count; i_poly++) { + MPoly *target_poly = cddm->mpoly + *(cddm->pmap[v_target].indices + i_poly); + + if (cddm_poly_compare(cddm->mloop, mp, target_poly, vtargetmap, +1) || + cddm_poly_compare(cddm->mloop, mp, target_poly, vtargetmap, -1)) + { + found = true; + break; } - pkey.hash_sum += v_target; - pkey.hash_xor ^= v_target; - pkey.totloops++; - v_prev = v_target; } - if (BLI_gset_haskey(poly_gset, &pkey)) { - - /* There might be a poly that matches this one. - * We could just leave it there and say there is, and do a "continue". - * ... but we are checking whether there is an exact poly match. - * It's not so costly in terms of CPU since it's very rare, just a lot of complex code. - */ - - /* Consider current loop again */ - ml = cddm->mloop + mp->loopstart; - /* Consider the target of the loop's first vert */ - v_target = vtargetmap[ml->v]; - /* Now see if v_target belongs to a poly that shares all vertices with source poly, - * in same order, or reverse order */ - - for (i_poly = 0; i_poly < cddm->pmap[v_target].count; i_poly++) { - MPoly *target_poly = cddm->mpoly + *(cddm->pmap[v_target].indices + i_poly); - - if (cddm_poly_compare(cddm->mloop, mp, target_poly, vtargetmap, +1) || - cddm_poly_compare(cddm->mloop, mp, target_poly, vtargetmap, -1)) - { - found = true; - break; - } - } - if (found) { - /* Current poly's vertices are mapped to a poly that is strictly identical */ - /* Current poly is dumped */ - continue; - } + if (found) { + /* Current poly's vertices are mapped to a poly that is strictly identical */ + /* Current poly is dumped */ + continue; } } } @@ -3207,32 +3207,121 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap, const int ml = cddm->mloop + mp->loopstart; c = 0; + MLoop *last_valid_ml = NULL; + MLoop *first_valid_ml = NULL; + bool need_edge_from_last_valid_ml = false; + bool need_edge_to_first_valid_ml = false; + int created_edges = 0; for (j = 0; j < mp->totloop; j++, ml++) { - unsigned int v1, v2; + uint mlv; + mlv = (vtargetmap[ml->v] != -1) ? vtargetmap[ml->v] : ml->v; +#ifndef NDEBUG + MLoop *next_ml = cddm->mloop + mp->loopstart + ((j + 1) % mp->totloop); + uint next_mlv = (vtargetmap[next_ml->v] != -1) ? vtargetmap[next_ml->v] : next_ml->v; med = cddm->medge + ml->e; - v1 = (vtargetmap[med->v1] != -1) ? vtargetmap[med->v1] : med->v1; - v2 = (vtargetmap[med->v2] != -1) ? vtargetmap[med->v2] : med->v2; - if (LIKELY(v1 != v2)) { + uint v1 = (vtargetmap[med->v1] != -1) ? vtargetmap[med->v1] : med->v1; + uint v2 = (vtargetmap[med->v2] != -1) ? vtargetmap[med->v2] : med->v2; + BLI_assert((mlv == v1 && next_mlv == v2) || (mlv == v2 && next_mlv == v1)); +#endif + /* A loop is only valid if its matching edge is, and it's not reusing a vertex already used by this poly. */ + if (LIKELY((newe[ml->e] != -1) && ((mv[mlv].flag & ME_VERT_TMP_TAG) == 0))) { + mv[mlv].flag |= ME_VERT_TMP_TAG; + + if (UNLIKELY(last_valid_ml != NULL && need_edge_from_last_valid_ml)) { + /* We need to create a new edge between last valid loop and this one! */ + void **val_p; + + v1 = (vtargetmap[last_valid_ml->v] != -1) ? vtargetmap[last_valid_ml->v] : last_valid_ml->v; + v2 = mlv; + BLI_assert(v1 != v2); + if (BLI_edgehash_ensure_p(ehash, v1, v2, &val_p)) { + last_valid_ml->e = GET_INT_FROM_POINTER(*val_p); + } + else { + const int new_eidx = STACK_SIZE(medge); + STACK_PUSH(olde, olde[last_valid_ml->e]); + STACK_PUSH(medge, cddm->medge[last_valid_ml->e]); + medge[new_eidx].v1 = last_valid_ml->v; + medge[new_eidx].v2 = ml->v; + /* DO NOT change newe mapping, could break actual values due to some deleted original edges. */ + *val_p = SET_INT_IN_POINTER(new_eidx); + created_edges++; + + last_valid_ml->e = new_eidx; + } + need_edge_from_last_valid_ml = false; + } + #ifdef USE_LOOPS newl[j + mp->loopstart] = STACK_SIZE(mloop); #endif STACK_PUSH(oldl, j + mp->loopstart); - STACK_PUSH(mloop, *ml); + last_valid_ml = STACK_PUSH_RET_PTR(mloop); + *last_valid_ml = *ml; + if (first_valid_ml == NULL) { + first_valid_ml = last_valid_ml; + } c++; + + /* We absolutely HAVE to handle edge index remapping here, otherwise potential newly created edges + * in that part of code make remapping later totally unreliable. */ + BLI_assert(newe[ml->e] != -1); + last_valid_ml->e = newe[ml->e]; + } + else { + if (last_valid_ml != NULL) { + need_edge_from_last_valid_ml = true; + } + else { + need_edge_to_first_valid_ml = true; + } } } + if (UNLIKELY(last_valid_ml != NULL && !ELEM(first_valid_ml, NULL, last_valid_ml) && + (need_edge_to_first_valid_ml || need_edge_from_last_valid_ml))) + { + /* We need to create a new edge between last valid loop and first valid one! */ + void **val_p; + + uint v1 = (vtargetmap[last_valid_ml->v] != -1) ? vtargetmap[last_valid_ml->v] : last_valid_ml->v; + uint v2 = (vtargetmap[first_valid_ml->v] != -1) ? vtargetmap[first_valid_ml->v] : first_valid_ml->v; + BLI_assert(v1 != v2); + if (BLI_edgehash_ensure_p(ehash, v1, v2, &val_p)) { + last_valid_ml->e = GET_INT_FROM_POINTER(*val_p); + } + else { + const int new_eidx = STACK_SIZE(medge); + STACK_PUSH(olde, olde[last_valid_ml->e]); + STACK_PUSH(medge, cddm->medge[last_valid_ml->e]); + medge[new_eidx].v1 = last_valid_ml->v; + medge[new_eidx].v2 = first_valid_ml->v; + /* DO NOT change newe mapping, could break actual values due to some deleted original edges. */ + *val_p = SET_INT_IN_POINTER(new_eidx); + created_edges++; + + last_valid_ml->e = new_eidx; + } + need_edge_to_first_valid_ml = need_edge_from_last_valid_ml = false; + } if (UNLIKELY(c == 0)) { + BLI_assert(created_edges == 0); continue; } else if (UNLIKELY(c < 3)) { STACK_DISCARD(oldl, c); STACK_DISCARD(mloop, c); + if (created_edges > 0) { + for (j = STACK_SIZE(medge) - created_edges; j < STACK_SIZE(medge); j++) { + BLI_edgehash_remove(ehash, medge[j].v1, medge[j].v2, NULL); + } + STACK_DISCARD(olde, created_edges); + STACK_DISCARD(medge, created_edges); + } continue; } - mp_new = STACK_PUSH_RET_PTR(mpoly); *mp_new = *mp; mp_new->totloop = c; @@ -3257,10 +3346,10 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap, const int /*update edge indices and copy customdata*/ med = medge; for (i = 0; i < cddm2->dm.numEdgeData; i++, med++) { - if (newv[med->v1] != -1) - med->v1 = newv[med->v1]; - if (newv[med->v2] != -1) - med->v2 = newv[med->v2]; + BLI_assert(newv[med->v1] != -1); + med->v1 = newv[med->v1]; + BLI_assert(newv[med->v2] != -1); + med->v2 = newv[med->v2]; /* Can happen in case vtargetmap contains some double chains, we do not support that. */ BLI_assert(med->v1 != med->v2); @@ -3271,11 +3360,10 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap, const int /*update loop indices and copy customdata*/ ml = mloop; for (i = 0; i < cddm2->dm.numLoopData; i++, ml++) { - if (newe[ml->e] != -1) - ml->e = newe[ml->e]; - if (newv[ml->v] != -1) - ml->v = newv[ml->v]; - + /* Edge remapping has already be done in main loop handling part above. */ + BLI_assert(newv[ml->v] != -1); + ml->v = newv[ml->v]; + CustomData_copy_data(&dm->loopData, &cddm2->dm.loopData, oldl[i], i, 1); } diff --git a/source/blender/blenkernel/intern/mesh_validate.c b/source/blender/blenkernel/intern/mesh_validate.c index ba890b005d8..4aeddbb4c45 100644 --- a/source/blender/blenkernel/intern/mesh_validate.c +++ b/source/blender/blenkernel/intern/mesh_validate.c @@ -584,8 +584,8 @@ bool BKE_mesh_validate_arrays(Mesh *mesh, int prev_e = ml->e; ml->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(edge_hash, v1, v2)); fix_flag.loops_edge = true; - PRINT_ERR("\tPoly %u has invalid edge reference (%d), fixed using edge %u\n", - sp->index, prev_e, ml->e); + PRINT_ERR("\tPoly %u has invalid edge reference (%d, is_removed: %d), fixed using edge %u\n", + sp->index, prev_e, IS_REMOVED_EDGE(me), ml->e); } else { PRINT_ERR("\tPoly %u has invalid edge reference (%u)\n", sp->index, ml->e); -- cgit v1.2.3 From 2eead82ce0e7c7c2eb5be252fbcdb62f2c1a30f9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 27 May 2017 14:03:15 +1000 Subject: CustomData: assert on bad arguments to free Assert the index is in-range for the layer type. --- source/blender/blenkernel/intern/customdata.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 331714301d5..0939d35ed8d 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -1944,17 +1944,16 @@ void *CustomData_add_layer_named(CustomData *data, int type, int alloctype, bool CustomData_free_layer(CustomData *data, int type, int totelem, int index) { - if (index < 0) { - return false; - } const int index_first = CustomData_get_layer_index(data, type); - if (index_first == -1) { - return false; - } - const int n = index - index_first; int i; + BLI_assert(index >= index_first); + if ((index_first == -1) || (n < 0)) { + return false; + } + BLI_assert(data->layers[index].type == type); + customData_free_layer__internal(&data->layers[index], totelem); for (i = index + 1; i < data->totlayer; ++i) -- cgit v1.2.3 From 7df5ed14b1b8a2699280072b6a5f0cefb3749935 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 27 May 2017 20:47:41 +1000 Subject: Release wasn't building, limit debug scope --- source/blender/blenkernel/intern/cdderivedmesh.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 3295cc69262..46a067ea0bc 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -3213,16 +3213,16 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap, const int bool need_edge_to_first_valid_ml = false; int created_edges = 0; for (j = 0; j < mp->totloop; j++, ml++) { - uint mlv; - - mlv = (vtargetmap[ml->v] != -1) ? vtargetmap[ml->v] : ml->v; + const uint mlv = (vtargetmap[ml->v] != -1) ? vtargetmap[ml->v] : ml->v; #ifndef NDEBUG - MLoop *next_ml = cddm->mloop + mp->loopstart + ((j + 1) % mp->totloop); - uint next_mlv = (vtargetmap[next_ml->v] != -1) ? vtargetmap[next_ml->v] : next_ml->v; - med = cddm->medge + ml->e; - uint v1 = (vtargetmap[med->v1] != -1) ? vtargetmap[med->v1] : med->v1; - uint v2 = (vtargetmap[med->v2] != -1) ? vtargetmap[med->v2] : med->v2; - BLI_assert((mlv == v1 && next_mlv == v2) || (mlv == v2 && next_mlv == v1)); + { + MLoop *next_ml = cddm->mloop + mp->loopstart + ((j + 1) % mp->totloop); + uint next_mlv = (vtargetmap[next_ml->v] != -1) ? vtargetmap[next_ml->v] : next_ml->v; + med = cddm->medge + ml->e; + uint v1 = (vtargetmap[med->v1] != -1) ? vtargetmap[med->v1] : med->v1; + uint v2 = (vtargetmap[med->v2] != -1) ? vtargetmap[med->v2] : med->v2; + BLI_assert((mlv == v1 && next_mlv == v2) || (mlv == v2 && next_mlv == v1)); + } #endif /* A loop is only valid if its matching edge is, and it's not reusing a vertex already used by this poly. */ if (LIKELY((newe[ml->e] != -1) && ((mv[mlv].flag & ME_VERT_TMP_TAG) == 0))) { @@ -3232,8 +3232,8 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap, const int /* We need to create a new edge between last valid loop and this one! */ void **val_p; - v1 = (vtargetmap[last_valid_ml->v] != -1) ? vtargetmap[last_valid_ml->v] : last_valid_ml->v; - v2 = mlv; + uint v1 = (vtargetmap[last_valid_ml->v] != -1) ? vtargetmap[last_valid_ml->v] : last_valid_ml->v; + uint v2 = mlv; BLI_assert(v1 != v2); if (BLI_edgehash_ensure_p(ehash, v1, v2, &val_p)) { last_valid_ml->e = GET_INT_FROM_POINTER(*val_p); -- cgit v1.2.3 From 9f044cb422c1fc9ad79278092445f612342abb59 Mon Sep 17 00:00:00 2001 From: Aaron Carlisle Date: Sat, 27 May 2017 15:34:55 -0400 Subject: Remove MinGW support The Issue ======= For a long time now MinGW has been unsupported and unmaintained and at this point, it looks like something that we should just leave behind and move on. Why Remove ========== One of the big motivations for MinGW back in the day is that it was free compared to MSVC which was licensed based. However, now that this is no longer true we have basically stopped updating the need CMake files. Along with the CMake files, there are several patches to the extern libs needed to make this work. For example, see: https://developer.blender.org/diffusion/B/browse/master/extern/carve/patches/mingw_w64.patch If we wanted to keep MinGW then we would need to make more custom patches to the external libs and this is not something our platform maintainers are willing to do. For example, here is the patches needed to build python: https://github.com/Alexpux/MINGW-packages/tree/master/mingw-w64-python3 Fixes T51301 Differential Revision: https://developer.blender.org/D2648 --- source/blender/blenkernel/BKE_global.h | 5 ----- source/blender/blenkernel/intern/writeframeserver.c | 4 ---- 2 files changed, 9 deletions(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h index 4bb2b950901..830518906ab 100644 --- a/source/blender/blenkernel/BKE_global.h +++ b/source/blender/blenkernel/BKE_global.h @@ -189,11 +189,6 @@ enum { # error Either __BIG_ENDIAN__ or __LITTLE_ENDIAN__ must be defined. #endif -/* there is really no good place for this */ -#if defined(FREE_WINDOWS) && ((__GNUC__ < 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ < 6))) -# error "Mingw requires GCC 4.6 minimum" -#endif - #define L_ENDIAN 1 #define B_ENDIAN 0 diff --git a/source/blender/blenkernel/intern/writeframeserver.c b/source/blender/blenkernel/intern/writeframeserver.c index 212af76a7e8..4757186f546 100644 --- a/source/blender/blenkernel/intern/writeframeserver.c +++ b/source/blender/blenkernel/intern/writeframeserver.c @@ -268,11 +268,7 @@ int BKE_frameserver_loop(void *context_v, RenderData *rd, ReportList *UNUSED(rep struct timeval tv; struct sockaddr_in addr; int len, rval; -#ifdef FREE_WINDOWS - int socklen; -#else unsigned int socklen; -#endif char buf[4096]; FrameserverContext *context = context_v; -- cgit v1.2.3