diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2016-12-15 13:56:59 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2016-12-15 13:56:59 +0300 |
commit | e3812b525f409d6f243c7ac6b1a52007148ad3e2 (patch) | |
tree | 7440b7afd99708606141366006a2e92270cc1003 /source/blender/blenkernel/intern | |
parent | 65b4a9f40339bbba1c8846e67e51b4a1df712d2e (diff) | |
parent | 665110a4140307b2ae4c96f682e09c7e846101c4 (diff) |
Merge branch 'master' into multi_previews_id
Conflicts:
source/blender/editors/interface/interface_widgets.c
Diffstat (limited to 'source/blender/blenkernel/intern')
29 files changed, 289 insertions, 288 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index ae18f5289d4..1f937d837b4 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -230,7 +230,9 @@ static MPoly *dm_dupPolyArray(DerivedMesh *dm) static int dm_getNumLoopTri(DerivedMesh *dm) { - return dm->looptris.num; + const int numlooptris = poly_to_tri_count(dm->getNumPolys(dm), dm->getNumLoops(dm)); + BLI_assert(ELEM(dm->looptris.num, 0, numlooptris)); + return numlooptris; } static CustomData *dm_getVertCData(DerivedMesh *dm) diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 04c00f115a8..ab8970c7d42 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -438,8 +438,8 @@ bPoseChannel *BKE_pose_channel_verify(bPose *pose, const char *name) chan->scaleIn = chan->scaleOut = 1.0f; - chan->limitmin[0] = chan->limitmin[1] = chan->limitmin[2] = -180.0f; - chan->limitmax[0] = chan->limitmax[1] = chan->limitmax[2] = 180.0f; + chan->limitmin[0] = chan->limitmin[1] = chan->limitmin[2] = -M_PI; + chan->limitmax[0] = chan->limitmax[1] = chan->limitmax[2] = M_PI; chan->stiffness[0] = chan->stiffness[1] = chan->stiffness[2] = 0.0f; chan->ikrotweight = chan->iklinweight = 0.0f; unit_m4(chan->constinv); diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index a5abc6beff8..21279392392 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -308,17 +308,19 @@ bool BKE_animdata_copy_id(ID *id_to, ID *id_from, const bool do_action) return true; } -void BKE_animdata_copy_id_action(ID *id) +void BKE_animdata_copy_id_action(ID *id, const bool set_newid) { AnimData *adt = BKE_animdata_from_id(id); if (adt) { if (adt->action) { id_us_min((ID *)adt->action); - adt->action = BKE_action_copy(G.main, adt->action); + adt->action = set_newid ? ID_NEW_SET(adt->action, BKE_action_copy(G.main, adt->action)) : + BKE_action_copy(G.main, adt->action); } if (adt->tmpact) { id_us_min((ID *)adt->tmpact); - adt->tmpact = BKE_action_copy(G.main, adt->tmpact); + adt->tmpact = set_newid ? ID_NEW_SET(adt->tmpact, BKE_action_copy(G.main, adt->tmpact)) : + BKE_action_copy(G.main, adt->tmpact); } } } diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index badfeaee6bd..2b333941c6e 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -1781,7 +1781,6 @@ static void pose_proxy_synchronize(Object *ob, Object *from, int layer_protected BLI_duplicatelist(&pose->agroups, &frompose->agroups); pose->active_group = frompose->active_group; - BKE_pose_channels_hash_make(frompose); for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) { pchanp = BKE_pose_channel_find_name(frompose, pchan->name); diff --git a/source/blender/blenkernel/intern/blender_undo.c b/source/blender/blenkernel/intern/blender_undo.c index d64bf7ecf43..bc98d6f6805 100644 --- a/source/blender/blenkernel/intern/blender_undo.c +++ b/source/blender/blenkernel/intern/blender_undo.c @@ -319,6 +319,13 @@ const char *BKE_undo_get_name(int nr, bool *r_active) return NULL; } +/* return the name of the last item */ +const char *BKE_undo_get_name_last(void) +{ + UndoElem *uel = undobase.last; + return (uel ? uel->name : NULL); +} + /** * Saves .blend using undo buffer. * diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c index 6da68470ecc..54f709a1e5b 100644 --- a/source/blender/blenkernel/intern/blendfile.c +++ b/source/blender/blenkernel/intern/blendfile.c @@ -407,9 +407,9 @@ bool BKE_blendfile_read_from_memfile( if (bfd) { /* remove the unused screens and wm */ while (bfd->main->wm.first) - BKE_libblock_free_ex(bfd->main, bfd->main->wm.first, true); + BKE_libblock_free_ex(bfd->main, bfd->main->wm.first, true, true); while (bfd->main->screen.first) - BKE_libblock_free_ex(bfd->main, bfd->main->screen.first, true); + BKE_libblock_free_ex(bfd->main, bfd->main->screen.first, true, true); setup_app_data(C, bfd, "<memory1>", reports); } diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 8ef1fae1155..0d509ecea06 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -249,6 +249,9 @@ void BKE_brush_make_local(Main *bmain, Brush *brush, const bool lib_local) brush_new->id.us = 0; + /* setting newid is mandatory for complex make_lib_local logic... */ + ID_NEW_SET(brush, brush_new); + if (!lib_local) { BKE_libblock_remap(bmain, brush, brush_new, ID_REMAP_SKIP_INDIRECT_USAGE); } diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index 85ce399b770..9cb553aa27b 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -252,7 +252,7 @@ void BKE_camera_params_from_view3d(CameraParams *params, const View3D *v3d, cons } else if (rv3d->persp == RV3D_ORTHO) { /* orthographic view */ - int sensor_size = BKE_camera_sensor_size(params->sensor_fit, params->sensor_x, params->sensor_y); + float sensor_size = BKE_camera_sensor_size(params->sensor_fit, params->sensor_x, params->sensor_y); params->clipend *= 0.5f; // otherwise too extreme low zbuffer quality params->clipsta = -params->clipend; @@ -337,6 +337,8 @@ void BKE_camera_params_compute_viewplane(CameraParams *params, int winx, int win viewplane.ymin *= pixsize; viewplane.ymax *= pixsize; + /* Used for rendering (offset by near-clip with perspective views), passed to RE_SetPixelSize. + * For viewport drawing 'RegionView3D.pixsize'. */ params->viewdx = pixsize; params->viewdy = params->ycor * pixsize; params->viewplane = viewplane; diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index b85f1b838ff..cb74dbcd8d1 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -4404,6 +4404,7 @@ static void transformcache_free(bConstraint *con) #ifdef WITH_ALEMBIC CacheReader_free(data->reader); #endif + data->reader = NULL; } } @@ -4705,27 +4706,6 @@ bConstraint *BKE_constraint_add_for_object(Object *ob, const char *name, short t /* ......... */ -/* helper for BKE_constraints_relink() - call ID_NEW() on every ID reference the constraint has */ -static void con_relink_id_cb(bConstraint *UNUSED(con), ID **idpoin, bool UNUSED(is_reference), void *UNUSED(userdata)) -{ - /* ID_NEW() expects a struct with inline "id" member as first - * since we've got the actual ID block, let's just inline this - * code. - * - * See ID_NEW(a) in DNA_ID.h - */ - if ((*idpoin) && (*idpoin)->newid) - (*idpoin) = (void *)(*idpoin)->newid; -} - -/* Reassign links that constraints have to other data (called during file loading?) */ -void BKE_constraints_relink(ListBase *conlist) -{ - /* just a wrapper around ID-loop for just calling ID_NEW() on all ID refs */ - BKE_constraints_id_loop(conlist, con_relink_id_cb, NULL); -} - - /* Run the given callback on all ID-blocks in list of constraints */ void BKE_constraints_id_loop(ListBase *conlist, ConstraintIDFunc func, void *userdata) { diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c index 02ae123a71e..a8341939692 100644 --- a/source/blender/blenkernel/intern/depsgraph.c +++ b/source/blender/blenkernel/intern/depsgraph.c @@ -800,6 +800,10 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Main *bmain, Sc /* Actual code uses get_collider_cache */ dag_add_collision_relations(dag, scene, ob, node, part->collision_group, ob->lay, eModifierType_Collision, NULL, true, "Particle Collision"); } + else if ((psys->flag & PSYS_HAIR_DYNAMICS) && psys->clmd && psys->clmd->coll_parms) { + /* Hair uses cloth simulation, i.e. get_collision_objects */ + dag_add_collision_relations(dag, scene, ob, node, psys->clmd->coll_parms->group, ob->lay | scene->lay, eModifierType_Collision, NULL, true, "Hair Collision"); + } dag_add_forcefield_relations(dag, scene, ob, node, part->effector_weights, part->type == PART_HAIR, 0, "Particle Force Field"); @@ -1428,7 +1432,6 @@ static void scene_sort_groups(Main *bmain, Scene *sce) /* test; are group objects all in this scene? */ for (ob = bmain->object.first; ob; ob = ob->id.next) { ob->id.tag &= ~LIB_TAG_DOIT; - ob->id.newid = NULL; /* newid abuse for GroupObject */ } for (base = sce->base.first; base; base = base->next) base->object->id.tag |= LIB_TAG_DOIT; @@ -1459,6 +1462,11 @@ static void scene_sort_groups(Main *bmain, Scene *sce) group->gobject = listb; } } + + /* newid abused for GroupObject, cleanup. */ + for (ob = bmain->object.first; ob; ob = ob->id.next) { + ob->id.newid = NULL; + } } static void dag_scene_tag_rebuild(Scene *sce) @@ -3284,7 +3292,7 @@ void DAG_threaded_update_handle_node_updated(void *node_v, for (itA = node->child; itA; itA = itA->next) { DagNode *child_node = itA->node; if (child_node != node) { - atomic_sub_uint32(&child_node->num_pending_parents, 1); + atomic_sub_and_fetch_uint32(&child_node->num_pending_parents, 1); if (child_node->num_pending_parents == 0) { bool need_schedule; diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index c7399047ed5..66070923153 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -2264,7 +2264,7 @@ static void dynamic_paint_create_uv_surface_neighbor_cb(void *userdata, const in * to non--1 *before* its tri_index is set (i.e. that it cannot be used a neighbour). */ tPoint->neighbour_pixel = ind - 1; - atomic_add_uint32(&tPoint->neighbour_pixel, 1); + atomic_add_and_fetch_uint32(&tPoint->neighbour_pixel, 1); tPoint->tri_index = i; /* Now calculate pixel data for this pixel as it was on polygon surface */ @@ -2289,7 +2289,7 @@ static void dynamic_paint_create_uv_surface_neighbor_cb(void *userdata, const in /* Increase the final number of active surface points if relevant. */ if (tPoint->tri_index != -1) - atomic_add_uint32(active_points, 1); + atomic_add_and_fetch_uint32(active_points, 1); } } diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c index 05cf5f6d7bd..e7c0e69b1cb 100644 --- a/source/blender/blenkernel/intern/editderivedmesh.c +++ b/source/blender/blenkernel/intern/editderivedmesh.c @@ -621,10 +621,33 @@ static void emDM_recalcTessellation(DerivedMesh *UNUSED(dm)) /* do nothing */ } -static void emDM_recalcLoopTri(DerivedMesh *UNUSED(dm)) +static void emDM_recalcLoopTri(DerivedMesh *dm) { - /* Nothing to do: emDM tessellation is known, - * allocate and fill in with emDM_getLoopTriArray */ + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; + BMLoop *(*looptris)[3] = bmdm->em->looptris; + MLoopTri *mlooptri; + const int tottri = bmdm->em->tottri; + int i; + + DM_ensure_looptri_data(dm); + mlooptri = dm->looptris.array; + + BLI_assert(poly_to_tri_count(dm->numPolyData, dm->numLoopData) == dm->looptris.num); + BLI_assert(tottri == dm->looptris.num); + + BM_mesh_elem_index_ensure(bmdm->em->bm, BM_FACE | BM_LOOP); + + for (i = 0; i < tottri; i++) { + BMLoop **ltri = looptris[i]; + MLoopTri *lt = &mlooptri[i]; + + ARRAY_SET_ITEMS( + lt->tri, + BM_elem_index_get(ltri[0]), + BM_elem_index_get(ltri[1]), + BM_elem_index_get(ltri[2])); + lt->poly = BM_elem_index_get(ltri[0]->f); + } } static const MLoopTri *emDM_getLoopTriArray(DerivedMesh *dm) @@ -633,32 +656,9 @@ static const MLoopTri *emDM_getLoopTriArray(DerivedMesh *dm) BLI_assert(poly_to_tri_count(dm->numPolyData, dm->numLoopData) == dm->looptris.num); } else { - EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; - BMLoop *(*looptris)[3] = bmdm->em->looptris; - MLoopTri *mlooptri; - const int tottri = bmdm->em->tottri; - int i; - - DM_ensure_looptri_data(dm); - mlooptri = dm->looptris.array; - - BLI_assert(poly_to_tri_count(dm->numPolyData, dm->numLoopData) == dm->looptris.num); - BLI_assert(tottri == dm->looptris.num); - - BM_mesh_elem_index_ensure(bmdm->em->bm, BM_FACE | BM_LOOP); - - for (i = 0; i < tottri; i++) { - BMLoop **ltri = looptris[i]; - MLoopTri *lt = &mlooptri[i]; - - ARRAY_SET_ITEMS( - lt->tri, - BM_elem_index_get(ltri[0]), - BM_elem_index_get(ltri[1]), - BM_elem_index_get(ltri[2])); - lt->poly = BM_elem_index_get(ltri[0]->f); - } + dm->recalcLoopTri(dm); } + return dm->looptris.array; } diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index 7e6897a2858..3e85b0d4a15 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -770,7 +770,7 @@ static void do_texture_effector(EffectorCache *eff, EffectorData *efd, EffectedP force[1] = (0.5f - result->tg) * strength; force[2] = (0.5f - result->tb) * strength; } - else { + else if (nabla != 0) { strength/=nabla; tex_co[0] += nabla; @@ -810,6 +810,9 @@ static void do_texture_effector(EffectorCache *eff, EffectorData *efd, EffectedP force[2] = (dgdx - drdy) * strength; } } + else { + zero_v3(force); + } if (eff->pd->flag & PFIELD_TEX_2D) { float fac = -dot_v3v3(force, efd->nor); diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index 2242113b79b..cd2eac078cf 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -382,7 +382,8 @@ bGPDpalette *BKE_gpencil_palette_addnew(bGPdata *gpd, const char *name, bool set sizeof(palette->info)); /* make this one the active one */ - if (setactive) { + /* NOTE: Always make this active if there's nothing else yet (T50123) */ + if ((setactive) || (gpd->palettes.first == gpd->palettes.last)) { BKE_gpencil_palette_setactive(gpd, palette); } @@ -1263,7 +1264,11 @@ void BKE_gpencil_palettecolor_changename(bGPdata *gpd, char *oldname, const char bGPDlayer *gpl; bGPDframe *gpf; bGPDstroke *gps; - + + /* Sanity checks (gpd may not be set in the RNA pointers sometimes) */ + if (ELEM(NULL, gpd, oldname, newname)) + return; + for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { for (gpf = gpl->frames.first; gpf; gpf = gpf->next) { for (gps = gpf->strokes.first; gps; gps = gps->next) { @@ -1282,7 +1287,11 @@ void BKE_gpencil_palettecolor_delete_strokes(struct bGPdata *gpd, char *name) bGPDlayer *gpl; bGPDframe *gpf; bGPDstroke *gps, *gpsn; - + + /* Sanity checks (gpd may not be set in the RNA pointers sometimes) */ + if (ELEM(NULL, gpd, name)) + return; + for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { for (gpf = gpl->frames.first; gpf; gpf = gpf->next) { for (gps = gpf->strokes.first; gps; gps = gpsn) { diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index df3a7630bb0..a2d94ccc478 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -436,7 +436,6 @@ static void copy_image_packedfiles(ListBase *lb_dst, const ListBase *lb_src) Image *BKE_image_copy(Main *bmain, Image *ima) { Image *nima = image_alloc(bmain, ima->id.name + 2, ima->source, ima->type); - ima->id.newid = &nima->id; BLI_strncpy(nima->name, ima->name, sizeof(ima->name)); @@ -1244,7 +1243,6 @@ char BKE_imtype_valid_channels(const char imtype, bool write_file) case R_IMF_IMTYPE_RAWTGA: case R_IMF_IMTYPE_IRIS: case R_IMF_IMTYPE_PNG: - case R_IMF_IMTYPE_RADHDR: case R_IMF_IMTYPE_TIFF: case R_IMF_IMTYPE_OPENEXR: case R_IMF_IMTYPE_MULTILAYER: diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index e5b066a3c26..65f37d0a5b1 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -263,6 +263,14 @@ void id_fake_user_clear(ID *id) } } +void BKE_id_clear_newpoin(ID *id) +{ + if (id->newid) { + id->newid->tag &= ~LIB_TAG_NEW; + } + id->newid = NULL; +} + static int id_expand_local_callback( void *UNUSED(user_data), struct ID *id_self, struct ID **id_pointer, int UNUSED(cd_flag)) { @@ -326,6 +334,17 @@ void BKE_id_make_local_generic(Main *bmain, ID *id, const bool id_in_mainlist, c if (id_copy(bmain, id, &id_new, false)) { id_new->us = 0; + /* setting newid is mandatory for complex make_lib_local logic... */ + ID_NEW_SET(id, id_new); + Key *key = BKE_key_from_id(id), *key_new = BKE_key_from_id(id); + if (key && key_new) { + ID_NEW_SET(key, key_new); + } + bNodeTree *ntree = ntreeFromID(id), *ntree_new = ntreeFromID(id_new); + if (ntree && ntree_new) { + ID_NEW_SET(ntree, ntree_new); + } + if (!lib_local) { BKE_libblock_remap(bmain, id, id_new, ID_REMAP_SKIP_INDIRECT_USAGE); } @@ -337,6 +356,8 @@ void BKE_id_make_local_generic(Main *bmain, ID *id, const bool id_in_mainlist, c /** * Calls the appropriate make_local method for the block, unless test is set. * + * \note Always set ID->newid pointer in case it gets duplicated... + * * \param lib_local Special flag used when making a whole library's content local, it needs specific handling. * * \return true if the block can be made local. @@ -561,6 +582,7 @@ bool id_copy(Main *bmain, ID *id, ID **newid, bool test) return false; } +/** Does *not* set ID->newid pointer. */ bool id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop) { ID *newid = NULL; @@ -571,11 +593,11 @@ bool id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop) if (RNA_property_editable(ptr, prop)) { if (id_copy(CTX_data_main(C), id, &newid, false) && newid) { /* copy animation actions too */ - BKE_animdata_copy_id_action(id); + BKE_animdata_copy_id_action(id, false); /* us is 1 by convention, but RNA_property_pointer_set * will also increment it, so set it to zero */ newid->us = 0; - + /* assign copy */ RNA_id_pointer_create(newid, &idptr); RNA_property_pointer_set(ptr, prop, idptr); @@ -1120,9 +1142,6 @@ void *BKE_libblock_copy(Main *bmain, ID *id) memcpy(cpn + sizeof(ID), cp + sizeof(ID), idn_len - sizeof(ID)); } - - id->newid = idn; - idn->tag |= LIB_TAG_NEW; BKE_libblock_copy_data(idn, id, false); @@ -1147,8 +1166,6 @@ void *BKE_libblock_copy_nolib(ID *id, const bool do_action) memcpy(cpn + sizeof(ID), cp + sizeof(ID), idn_len - sizeof(ID)); } - id->newid = idn; - idn->tag |= LIB_TAG_NEW; idn->us = 1; BKE_libblock_copy_data(idn, id, do_action); @@ -1156,31 +1173,6 @@ void *BKE_libblock_copy_nolib(ID *id, const bool do_action) return idn; } -static int id_relink_looper(void *UNUSED(user_data), ID *UNUSED(self_id), ID **id_pointer, const int cd_flag) -{ - ID *id = *id_pointer; - if (id) { - /* See: NEW_ID macro */ - if (id->newid) { - BKE_library_update_ID_link_user(id->newid, id, cd_flag); - *id_pointer = id->newid; - } - else if (id->tag & LIB_TAG_NEW) { - id->tag &= ~LIB_TAG_NEW; - BKE_libblock_relink(id); - } - } - return IDWALK_RET_NOP; -} - -void BKE_libblock_relink(ID *id) -{ - if (ID_IS_LINKED_DATABLOCK(id)) - return; - - BKE_library_foreach_ID_link(id, id_relink_looper, NULL, 0); -} - void BKE_library_free(Library *lib) { if (lib->packedfile) @@ -1211,46 +1203,46 @@ void BKE_main_free(Main *mainvar) while ( (id = lb->first) ) { #if 1 - BKE_libblock_free_ex(mainvar, id, false); + BKE_libblock_free_ex(mainvar, id, false, false); #else /* errors freeing ID's can be hard to track down, * enable this so valgrind will give the line number in its error log */ switch (a) { - case 0: BKE_libblock_free_ex(mainvar, id, false); break; - case 1: BKE_libblock_free_ex(mainvar, id, false); break; - case 2: BKE_libblock_free_ex(mainvar, id, false); break; - case 3: BKE_libblock_free_ex(mainvar, id, false); break; - case 4: BKE_libblock_free_ex(mainvar, id, false); break; - case 5: BKE_libblock_free_ex(mainvar, id, false); break; - case 6: BKE_libblock_free_ex(mainvar, id, false); break; - case 7: BKE_libblock_free_ex(mainvar, id, false); break; - case 8: BKE_libblock_free_ex(mainvar, id, false); break; - case 9: BKE_libblock_free_ex(mainvar, id, false); break; - case 10: BKE_libblock_free_ex(mainvar, id, false); break; - case 11: BKE_libblock_free_ex(mainvar, id, false); break; - case 12: BKE_libblock_free_ex(mainvar, id, false); break; - case 13: BKE_libblock_free_ex(mainvar, id, false); break; - case 14: BKE_libblock_free_ex(mainvar, id, false); break; - case 15: BKE_libblock_free_ex(mainvar, id, false); break; - case 16: BKE_libblock_free_ex(mainvar, id, false); break; - case 17: BKE_libblock_free_ex(mainvar, id, false); break; - case 18: BKE_libblock_free_ex(mainvar, id, false); break; - case 19: BKE_libblock_free_ex(mainvar, id, false); break; - case 20: BKE_libblock_free_ex(mainvar, id, false); break; - case 21: BKE_libblock_free_ex(mainvar, id, false); break; - case 22: BKE_libblock_free_ex(mainvar, id, false); break; - case 23: BKE_libblock_free_ex(mainvar, id, false); break; - case 24: BKE_libblock_free_ex(mainvar, id, false); break; - case 25: BKE_libblock_free_ex(mainvar, id, false); break; - case 26: BKE_libblock_free_ex(mainvar, id, false); break; - case 27: BKE_libblock_free_ex(mainvar, id, false); break; - case 28: BKE_libblock_free_ex(mainvar, id, false); break; - case 29: BKE_libblock_free_ex(mainvar, id, false); break; - case 30: BKE_libblock_free_ex(mainvar, id, false); break; - case 31: BKE_libblock_free_ex(mainvar, id, false); break; - case 32: BKE_libblock_free_ex(mainvar, id, false); break; - case 33: BKE_libblock_free_ex(mainvar, id, false); break; - case 34: BKE_libblock_free_ex(mainvar, id, false); break; + case 0: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 1: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 2: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 3: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 4: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 5: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 6: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 7: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 8: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 9: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 10: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 11: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 12: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 13: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 14: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 15: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 16: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 17: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 18: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 19: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 20: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 21: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 22: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 23: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 24: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 25: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 26: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 27: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 28: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 29: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 30: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 31: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 32: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 33: BKE_libblock_free_ex(mainvar, id, false, false); break; + case 34: BKE_libblock_free_ex(mainvar, id, false, false); break; default: BLI_assert(0); break; @@ -1662,7 +1654,6 @@ void BKE_library_make_local( const bool do_skip = (id && !BKE_idcode_is_linkable(GS(id->name))); for (; id; id = id->next) { - id->newid = NULL; id->tag &= ~LIB_TAG_DOIT; if (id->lib == NULL) { @@ -1852,7 +1843,7 @@ void BKE_library_make_local( * However, this is a highly-risky presumption, and nice crasher in case something goes wrong here. * So for 2.78a will keep the safe option, and switch to more efficient one in master later. */ #if 1 - BKE_libblock_free_ex(bmain, id, false); + BKE_libblock_free_ex(bmain, id, false, true); #else BKE_libblock_unlink(bmain, id, false, false); BKE_libblock_free(bmain, id); @@ -1862,6 +1853,7 @@ void BKE_library_make_local( } } + BKE_main_id_clear_newpoins(bmain); BLI_memarena_free(linklist_mem); } diff --git a/source/blender/blenkernel/intern/library_remap.c b/source/blender/blenkernel/intern/library_remap.c index b468e6436c8..4f1f6d963ed 100644 --- a/source/blender/blenkernel/intern/library_remap.c +++ b/source/blender/blenkernel/intern/library_remap.c @@ -378,6 +378,18 @@ static void libblock_remap_data_postprocess_obdata_relink(Main *UNUSED(bmain), O } } +static void libblock_remap_data_postprocess_nodetree_update(Main *bmain, ID *new_id) +{ + /* Verify all nodetree user nodes. */ + ntreeVerifyNodes(bmain, new_id); + + /* Update node trees as necessary. */ + FOREACH_NODETREE(bmain, ntree, id) { + /* make an update call for the tree */ + ntreeUpdateTree(bmain, ntree); + } FOREACH_NODETREE_END +} + /** * Execute the 'data' part of the remapping (that is, all ID pointers from other ID datablocks). * @@ -551,6 +563,8 @@ void BKE_libblock_remap_locked( default: break; } + /* Node trees may virtually use any kind of data-block... */ + libblock_remap_data_postprocess_nodetree_update(bmain, new_id); /* Full rebuild of DAG! */ DAG_relations_tag_update(bmain); @@ -666,46 +680,52 @@ void BKE_libblock_relink_ex( } } -static void animdata_dtar_clear_cb(ID *UNUSED(id), AnimData *adt, void *userdata) +static int id_relink_to_newid_looper(void *UNUSED(user_data), ID *UNUSED(self_id), ID **id_pointer, const int cd_flag) { - ChannelDriver *driver; - FCurve *fcu; - - /* find the driver this belongs to and update it */ - for (fcu = adt->drivers.first; fcu; fcu = fcu->next) { - driver = fcu->driver; - - if (driver) { - DriverVar *dvar; - for (dvar = driver->variables.first; dvar; dvar = dvar->next) { - DRIVER_TARGETS_USED_LOOPER(dvar) - { - if (dtar->id == userdata) - dtar->id = NULL; - } - DRIVER_TARGETS_LOOPER_END - } + ID *id = *id_pointer; + if (id) { + /* See: NEW_ID macro */ + if (id->newid) { + BKE_library_update_ID_link_user(id->newid, id, cd_flag); + *id_pointer = id->newid; + } + else if (id->tag & LIB_TAG_NEW) { + id->tag &= ~LIB_TAG_NEW; + BKE_libblock_relink_to_newid(id); } } + return IDWALK_RET_NOP; +} + +/** Similar to libblock_relink_ex, but is remapping IDs to their newid value if non-NULL, in given \a id. + * + * Very specific usage, not sure we'll keep it on the long run, currently only used in Object duplication code... + */ +void BKE_libblock_relink_to_newid(ID *id) +{ + if (ID_IS_LINKED_DATABLOCK(id)) + return; + + BKE_library_foreach_ID_link(id, id_relink_to_newid_looper, NULL, 0); } -void BKE_libblock_free_data(Main *bmain, ID *id) +void BKE_libblock_free_data(Main *UNUSED(bmain), ID *id) { if (id->properties) { IDP_FreeProperty(id->properties); MEM_freeN(id->properties); } - - /* this ID may be a driver target! */ - BKE_animdata_main_cb(bmain, animdata_dtar_clear_cb, (void *)id); } /** * used in headerbuttons.c image.c mesh.c screen.c sound.c and library.c * * \param do_id_user: if \a true, try to release other ID's 'references' hold by \a idv. + * (only applies to main database) + * \param do_ui_user: similar to do_id_user but makes sure UI does not hold references to + * \a id. */ -void BKE_libblock_free_ex(Main *bmain, void *idv, const bool do_id_user) +void BKE_libblock_free_ex(Main *bmain, void *idv, const bool do_id_user, const bool do_ui_user) { ID *id = idv; short type = GS(id->name); @@ -830,12 +850,14 @@ void BKE_libblock_free_ex(Main *bmain, void *idv, const bool do_id_user) /* avoid notifying on removed data */ BKE_main_lock(bmain); - if (free_notifier_reference_cb) { - free_notifier_reference_cb(id); - } + if (do_ui_user) { + if (free_notifier_reference_cb) { + free_notifier_reference_cb(id); + } - if (remap_editor_id_reference_cb) { - remap_editor_id_reference_cb(id, NULL); + if (remap_editor_id_reference_cb) { + remap_editor_id_reference_cb(id, NULL); + } } BLI_remlink(lb, id); @@ -848,7 +870,7 @@ void BKE_libblock_free_ex(Main *bmain, void *idv, const bool do_id_user) void BKE_libblock_free(Main *bmain, void *idv) { - BKE_libblock_free_ex(bmain, idv, true); + BKE_libblock_free_ex(bmain, idv, true, true); } void BKE_libblock_free_us(Main *bmain, void *idv) /* test users */ diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c index 016c9c863f0..a3fe73e4b11 100644 --- a/source/blender/blenkernel/intern/mesh_evaluate.c +++ b/source/blender/blenkernel/intern/mesh_evaluate.c @@ -238,7 +238,7 @@ static void mesh_calc_normals_poly_accum_task_cb(void *userdata, const int pidx) /* accumulate */ for (int k = 3; k--; ) { - atomic_add_fl(&vnors[ml[i].v][k], pnor[k] * fac); + atomic_add_and_fetch_fl(&vnors[ml[i].v][k], pnor[k] * fac); } prev_edge = cur_edge; } diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 2b88ae4823c..f16e8f328d4 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -736,11 +736,14 @@ void nodeRemoveAllSockets(bNodeTree *ntree, bNode *node) node_socket_free(ntree, sock, node); MEM_freeN(sock); } + BLI_listbase_clear(&node->inputs); + for (sock = node->outputs.first; sock; sock = sock_next) { sock_next = sock->next; node_socket_free(ntree, sock, node); MEM_freeN(sock); } + BLI_listbase_clear(&node->outputs); node->update |= NODE_UPDATE; } @@ -1304,33 +1307,6 @@ bNodeTree *ntreeCopyTree(Main *bmain, bNodeTree *ntree) return ntreeCopyTree_ex(ntree, bmain, true); } -/* use when duplicating scenes */ -void ntreeSwitchID_ex(bNodeTree *ntree, ID *id_from, ID *id_to, const bool do_id_user) -{ - bNode *node; - - if (id_from == id_to) { - /* should never happen but may as well skip if it does */ - return; - } - - /* for scene duplication only */ - for (node = ntree->nodes.first; node; node = node->next) { - if (node->id == id_from) { - if (do_id_user) { - id_us_min(id_from); - id_us_plus(id_to); - } - - node->id = id_to; - } - } -} -void ntreeSwitchID(bNodeTree *ntree, ID *id_from, ID *id_to) -{ - ntreeSwitchID_ex(ntree, id_from, id_to, true); -} - void ntreeUserIncrefID(bNodeTree *ntree) { bNode *node; diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 5bcf31ba45b..c6666ec5ced 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -1215,6 +1215,9 @@ void BKE_object_make_local_ex(Main *bmain, Object *ob, const bool lib_local, con ob_new->id.us = 0; ob_new->proxy = ob_new->proxy_from = ob_new->proxy_group = NULL; + /* setting newid is mandatory for complex make_lib_local logic... */ + ID_NEW_SET(ob, ob_new); + if (!lib_local) { BKE_libblock_remap(bmain, ob, ob_new, ID_REMAP_SKIP_INDIRECT_USAGE); } @@ -1347,7 +1350,10 @@ void BKE_object_make_proxy(Object *ob, Object *target, Object *gob) ob->type = target->type; ob->data = target->data; id_us_plus((ID *)ob->data); /* ensures lib data becomes LIB_TAG_EXTERN */ - + + /* copy vertex groups */ + defgroup_copy_list(&ob->defbase, &target->defbase); + /* copy material and index information */ ob->actcol = ob->totcol = 0; if (ob->mat) MEM_freeN(ob->mat); diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c index 14cc5ec0849..e3b801b3193 100644 --- a/source/blender/blenkernel/intern/object_dupli.c +++ b/source/blender/blenkernel/intern/object_dupli.c @@ -642,8 +642,7 @@ static void make_duplis_font(const DupliContext *ctx) float rmat[4][4]; zero_v3(obmat[3]); - unit_m4(rmat); - rotate_m4(rmat, 'Z', -ct->rot); + axis_angle_to_mat4_single(rmat, 'Z', -ct->rot); mul_m4_m4m4(obmat, obmat, rmat); } diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c index ff69f381b06..4fe4d6e75a6 100644 --- a/source/blender/blenkernel/intern/pbvh.c +++ b/source/blender/blenkernel/intern/pbvh.c @@ -977,7 +977,7 @@ static void pbvh_update_normals_accum_task_cb(void *userdata, const int n) * Not exact equivalent though, since atomicity is only ensured for one component * of the vector at a time, but here it shall not make any sensible difference. */ for (int k = 3; k--; ) { - atomic_add_fl(&vnors[v][k], fn[k]); + atomic_add_and_fetch_fl(&vnors[v][k], fn[k]); } } } diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index ebf9f017731..b5f34a29ebb 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -46,6 +46,7 @@ # include "RBI_api.h" #endif +#include "DNA_ID.h" #include "DNA_group_types.h" #include "DNA_meshdata_types.h" #include "DNA_object_types.h" @@ -222,13 +223,6 @@ RigidBodyCon *BKE_rigidbody_copy_constraint(Object *ob) return rbcN; } -/* preserve relationships between constraints and rigid bodies after duplication */ -void BKE_rigidbody_relink_constraint(RigidBodyCon *rbc) -{ - ID_NEW(rbc->ob1); - ID_NEW(rbc->ob2); -} - /* ************************************** */ /* Setup Utilities - Validate Sim Instances */ @@ -973,12 +967,9 @@ RigidBodyWorld *BKE_rigidbody_world_copy(RigidBodyWorld *rbw) void BKE_rigidbody_world_groups_relink(RigidBodyWorld *rbw) { - if (rbw->group && rbw->group->id.newid) - rbw->group = (Group *)rbw->group->id.newid; - if (rbw->constraints && rbw->constraints->id.newid) - rbw->constraints = (Group *)rbw->constraints->id.newid; - if (rbw->effector_weights->group && rbw->effector_weights->group->id.newid) - rbw->effector_weights->group = (Group *)rbw->effector_weights->group->id.newid; + ID_NEW_REMAP(rbw->group); + ID_NEW_REMAP(rbw->constraints); + ID_NEW_REMAP(rbw->effector_weights->group); } void BKE_rigidbody_world_id_loop(RigidBodyWorld *rbw, RigidbodyWorldIDFunc func, void *userdata) @@ -1633,7 +1624,6 @@ void BKE_rigidbody_do_simulation(Scene *scene, float ctime) struct RigidBodyOb *BKE_rigidbody_copy_object(Object *ob) { return NULL; } struct RigidBodyCon *BKE_rigidbody_copy_constraint(Object *ob) { return NULL; } -void BKE_rigidbody_relink_constraint(RigidBodyCon *rbc) {} void BKE_rigidbody_validate_sim_world(Scene *scene, RigidBodyWorld *rbw, bool rebuild) {} void BKE_rigidbody_calc_volume(Object *ob, float *r_vol) { if (r_vol) *r_vol = 0.0f; } void BKE_rigidbody_calc_center_of_mass(Object *ob, float r_center[3]) { zero_v3(r_center); } diff --git a/source/blender/blenkernel/intern/sca.c b/source/blender/blenkernel/intern/sca.c index c7f406089d9..fa221348932 100644 --- a/source/blender/blenkernel/intern/sca.c +++ b/source/blender/blenkernel/intern/sca.c @@ -602,41 +602,41 @@ void set_sca_new_poins_ob(Object *ob) if (act->flag & ACT_NEW) { if (act->type==ACT_EDIT_OBJECT) { bEditObjectActuator *eoa= act->data; - ID_NEW(eoa->ob); + ID_NEW_REMAP(eoa->ob); } else if (act->type==ACT_SCENE) { bSceneActuator *sca= act->data; - ID_NEW(sca->camera); + ID_NEW_REMAP(sca->camera); } else if (act->type==ACT_CAMERA) { bCameraActuator *ca= act->data; - ID_NEW(ca->ob); + ID_NEW_REMAP(ca->ob); } else if (act->type==ACT_OBJECT) { bObjectActuator *oa= act->data; - ID_NEW(oa->reference); + ID_NEW_REMAP(oa->reference); } else if (act->type==ACT_MESSAGE) { bMessageActuator *ma= act->data; - ID_NEW(ma->toObject); + ID_NEW_REMAP(ma->toObject); } else if (act->type==ACT_PARENT) { bParentActuator *para = act->data; - ID_NEW(para->ob); + ID_NEW_REMAP(para->ob); } else if (act->type==ACT_ARMATURE) { bArmatureActuator *aa = act->data; - ID_NEW(aa->target); - ID_NEW(aa->subtarget); + ID_NEW_REMAP(aa->target); + ID_NEW_REMAP(aa->subtarget); } else if (act->type==ACT_PROPERTY) { bPropertyActuator *pa= act->data; - ID_NEW(pa->ob); + ID_NEW_REMAP(pa->ob); } else if (act->type==ACT_STEERING) { bSteeringActuator *sta = act->data; - ID_NEW(sta->navmesh); - ID_NEW(sta->target); + ID_NEW_REMAP(sta->navmesh); + ID_NEW_REMAP(sta->target); } } act= act->next; diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 6e1f11cb526..091b8100d27 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -78,6 +78,7 @@ #include "BKE_idprop.h" #include "BKE_image.h" #include "BKE_library.h" +#include "BKE_library_remap.h" #include "BKE_linestyle.h" #include "BKE_main.h" #include "BKE_mask.h" @@ -186,8 +187,6 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type) scen = BKE_libblock_copy(bmain, &sce->id); BLI_duplicatelist(&(scen->base), &(sce->base)); - BKE_main_id_clear_newpoins(bmain); - id_us_plus((ID *)scen->world); id_us_plus((ID *)scen->set); /* id_us_plus((ID *)scen->gm.dome.warptext); */ /* XXX Not refcounted? see readfile.c */ @@ -211,7 +210,7 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type) if (sce->nodetree) { /* ID's are managed on both copy and switch */ scen->nodetree = ntreeCopyTree(bmain, sce->nodetree); - ntreeSwitchID(scen->nodetree, &sce->id, &scen->id); + BKE_libblock_relink_ex(bmain, scen->nodetree, &sce->id, &scen->id, false); } obase = sce->base.first; @@ -225,7 +224,7 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type) } /* copy action and remove animation used by sequencer */ - BKE_animdata_copy_id_action(&scen->id); + BKE_animdata_copy_id_action(&scen->id, false); if (type != SCE_COPY_FULL) remove_sequencer_fcurves(scen); @@ -318,7 +317,7 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type) /* camera */ if (type == SCE_COPY_LINK_DATA || type == SCE_COPY_FULL) { - ID_NEW(scen->camera); + ID_NEW_REMAP(scen->camera); } /* before scene copy */ @@ -329,7 +328,7 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type) if (scen->world) { id_us_plus((ID *)scen->world); scen->world = BKE_world_copy(bmain, scen->world); - BKE_animdata_copy_id_action((ID *)scen->world); + BKE_animdata_copy_id_action((ID *)scen->world, false); } if (sce->ed) { diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c index ce7c520438a..298671beedb 100644 --- a/source/blender/blenkernel/intern/seqeffects.c +++ b/source/blender/blenkernel/intern/seqeffects.c @@ -1074,29 +1074,31 @@ static void do_sub_effect(const SeqRenderData *context, Sequence *UNUSED(seq), f static void do_drop_effect_byte(float facf0, float facf1, int x, int y, unsigned char *rect2i, unsigned char *rect1i, unsigned char *outi) { - int height, width, temp, fac, fac1, fac2; + int temp, fac, fac1, fac2; unsigned char *rt1, *rt2, *out; int field = 1; - width = x; - height = y; + const int width = x; + const int height = y; + const int xoff = min_ii(XOFF, width); + const int yoff = min_ii(YOFF, height); fac1 = (int) (70.0f * facf0); fac2 = (int) (70.0f * facf1); - rt2 = (unsigned char *) (rect2i + YOFF * width); - rt1 = (unsigned char *) rect1i; - out = (unsigned char *) outi; - for (y = 0; y < height - YOFF; y++) { + rt2 = rect2i + yoff * 4 * width; + rt1 = rect1i; + out = outi; + for (y = 0; y < height - yoff; y++) { if (field) fac = fac1; else fac = fac2; field = !field; - memcpy(out, rt1, sizeof(int) * XOFF); - rt1 += XOFF * 4; - out += XOFF * 4; + memcpy(out, rt1, sizeof(*out) * xoff * 4); + rt1 += xoff * 4; + out += xoff * 4; - for (x = XOFF; x < width; x++) { + for (x = xoff; x < width; x++) { temp = ((fac * rt2[3]) >> 8); *(out++) = MAX2(0, *rt1 - temp); rt1++; @@ -1105,37 +1107,38 @@ static void do_drop_effect_byte(float facf0, float facf1, int x, int y, unsigned *(out++) = MAX2(0, *rt1 - temp); rt1++; rt2 += 4; } - rt2 += XOFF * 4; + rt2 += xoff * 4; } - memcpy(out, rt1, sizeof(int) * YOFF * width); + memcpy(out, rt1, sizeof(*out) * yoff * 4 * width); } static void do_drop_effect_float(float facf0, float facf1, int x, int y, float *rect2i, float *rect1i, float *outi) { - int height, width; float temp, fac, fac1, fac2; float *rt1, *rt2, *out; int field = 1; - width = x; - height = y; + const int width = x; + const int height = y; + const int xoff = min_ii(XOFF, width); + const int yoff = min_ii(YOFF, height); fac1 = 70.0f * facf0; fac2 = 70.0f * facf1; - rt2 = (rect2i + YOFF * width); + rt2 = rect2i + yoff * 4 * width; rt1 = rect1i; out = outi; - for (y = 0; y < height - YOFF; y++) { + for (y = 0; y < height - yoff; y++) { if (field) fac = fac1; else fac = fac2; field = !field; - memcpy(out, rt1, 4 * sizeof(float) * XOFF); - rt1 += XOFF * 4; - out += XOFF * 4; + memcpy(out, rt1, sizeof(*out) * xoff * 4); + rt1 += xoff * 4; + out += xoff * 4; - for (x = XOFF; x < width; x++) { + for (x = xoff; x < width; x++) { temp = fac * rt2[3]; *(out++) = MAX2(0.0f, *rt1 - temp); rt1++; @@ -1144,9 +1147,9 @@ static void do_drop_effect_float(float facf0, float facf1, int x, int y, float * *(out++) = MAX2(0.0f, *rt1 - temp); rt1++; rt2 += 4; } - rt2 += XOFF * 4; + rt2 += xoff * 4; } - memcpy(out, rt1, 4 * sizeof(float) * YOFF * width); + memcpy(out, rt1, sizeof(*out) * yoff * 4 * width); } /*********************** Mul *************************/ diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 65d751a8a72..1d2f5aee440 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -320,7 +320,8 @@ void BKE_sequencer_free_clipboard(void) /* Manage pointers in the clipboard. * note that these pointers should _never_ be access in the sequencer, * they are only for storage while in the clipboard - * notice 'newid' is used for temp pointer storage here, validate on access. + * notice 'newid' is used for temp pointer storage here, validate on access (this is safe usage, + * since those datablocks are fully out of Main lists). */ #define ID_PT (*id_pt) static void seqclipboard_ptr_free(ID **id_pt) diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 6d57c5f09e8..c4665c40ec4 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -4474,46 +4474,46 @@ static void ccgDM_recalcTessellation(DerivedMesh *UNUSED(dm)) /* Nothing to do: CCG handles creating its own tessfaces */ } -static void ccgDM_recalcLoopTri(DerivedMesh *UNUSED(dm)) +static void ccgDM_recalcLoopTri(DerivedMesh *dm) { - /* Nothing to do: CCG tessellation is known, - * allocate and fill in with ccgDM_getLoopTriArray */ + BLI_rw_mutex_lock(&loops_cache_rwlock, THREAD_LOCK_WRITE); + MLoopTri *mlooptri; + const int tottri = dm->numPolyData * 2; + int i, poly_index; + + DM_ensure_looptri_data(dm); + mlooptri = dm->looptris.array; + + BLI_assert(poly_to_tri_count(dm->numPolyData, dm->numLoopData) == dm->looptris.num); + BLI_assert(tottri == dm->looptris.num); + + for (i = 0, poly_index = 0; i < tottri; i += 2, poly_index += 1) { + MLoopTri *lt; + lt = &mlooptri[i]; + /* quad is (0, 3, 2, 1) */ + lt->tri[0] = (poly_index * 4) + 0; + lt->tri[1] = (poly_index * 4) + 2; + lt->tri[2] = (poly_index * 4) + 3; + lt->poly = poly_index; + + lt = &mlooptri[i + 1]; + lt->tri[0] = (poly_index * 4) + 0; + lt->tri[1] = (poly_index * 4) + 1; + lt->tri[2] = (poly_index * 4) + 2; + lt->poly = poly_index; + } + BLI_rw_mutex_unlock(&loops_cache_rwlock); } static const MLoopTri *ccgDM_getLoopTriArray(DerivedMesh *dm) { - BLI_rw_mutex_lock(&loops_cache_rwlock, THREAD_LOCK_WRITE); if (dm->looptris.array) { BLI_assert(poly_to_tri_count(dm->numPolyData, dm->numLoopData) == dm->looptris.num); } else { - MLoopTri *mlooptri; - const int tottri = dm->numPolyData * 2; - int i, poly_index; - - DM_ensure_looptri_data(dm); - mlooptri = dm->looptris.array; - - BLI_assert(poly_to_tri_count(dm->numPolyData, dm->numLoopData) == dm->looptris.num); - BLI_assert(tottri == dm->looptris.num); - - for (i = 0, poly_index = 0; i < tottri; i += 2, poly_index += 1) { - MLoopTri *lt; - lt = &mlooptri[i]; - /* quad is (0, 3, 2, 1) */ - lt->tri[0] = (poly_index * 4) + 0; - lt->tri[1] = (poly_index * 4) + 2; - lt->tri[2] = (poly_index * 4) + 3; - lt->poly = poly_index; - - lt = &mlooptri[i + 1]; - lt->tri[0] = (poly_index * 4) + 0; - lt->tri[1] = (poly_index * 4) + 1; - lt->tri[2] = (poly_index * 4) + 2; - lt->poly = poly_index; - } + dm->recalcLoopTri(dm); } - BLI_rw_mutex_unlock(&loops_cache_rwlock); + return dm->looptris.array; } diff --git a/source/blender/blenkernel/intern/tracking_stabilize.c b/source/blender/blenkernel/intern/tracking_stabilize.c index b8949f9a0de..36b24fbb2dc 100644 --- a/source/blender/blenkernel/intern/tracking_stabilize.c +++ b/source/blender/blenkernel/intern/tracking_stabilize.c @@ -587,7 +587,7 @@ static void compensate_rotation_center(const int size, float aspect, copy_v2_v2(intended_pivot, pivot); copy_v2_v2(rotated_pivot, pivot); - rotate_m2(rotation_mat, +angle); + angle_to_mat2(rotation_mat, +angle); sub_v2_v2(rotated_pivot, origin); mul_m2v2(rotation_mat, rotated_pivot); mul_v2_fl(rotated_pivot, scale); @@ -967,7 +967,7 @@ static void initialize_track_for_stabilization(StabContext *ctx, pos[0] *= aspect; angle = average_angle - atan2f(pos[1],pos[0]); - rotate_m2(local_data->stabilization_rotation_base, angle); + angle_to_mat2(local_data->stabilization_rotation_base, angle); /* Per track baseline value for zoom. */ len = len_v2(pos) + SCALE_ERROR_LIMIT_BIAS; |