Fix (IRC reported by Sergey) assert regarding icon_id of newly copied datablocks.
BKE_previewimg_copy() would simply copy PreviewImage's icon_id, without bothering about ID one. When we duplicate an ID, we want to reset its icon_id to zero (and regenerate it on-demand), not keep same icon_id as original, so added new BKE_previewimg_id_copy helper to handle that.
This commit is contained in:
@@ -99,6 +99,8 @@ struct PreviewImage *BKE_previewimg_create(void);
|
||||
/* create a copy of the preview image */
|
||||
struct PreviewImage *BKE_previewimg_copy(struct PreviewImage *prv);
|
||||
|
||||
void BKE_previewimg_id_copy(struct ID *new_id, struct ID *old_id);
|
||||
|
||||
/* retrieve existing or create new preview image */
|
||||
struct PreviewImage *BKE_previewimg_id_ensure(struct ID *id);
|
||||
|
||||
|
||||
@@ -221,6 +221,24 @@ PreviewImage *BKE_previewimg_copy(PreviewImage *prv)
|
||||
return prv_img;
|
||||
}
|
||||
|
||||
/** Duplicate preview image from \a id and clear icon_id, to be used by datablock copy functions. */
|
||||
void BKE_previewimg_id_copy(ID *new_id, ID *old_id)
|
||||
{
|
||||
PreviewImage **old_prv_p = BKE_previewimg_id_get_p(old_id);
|
||||
PreviewImage **new_prv_p = BKE_previewimg_id_get_p(new_id);
|
||||
|
||||
if (old_prv_p && *old_prv_p) {
|
||||
BLI_assert(new_prv_p != NULL && ELEM(*new_prv_p, NULL, *old_prv_p));
|
||||
// const int new_icon_id = get_next_free_id();
|
||||
|
||||
// if (new_icon_id == 0) {
|
||||
// return; /* Failure. */
|
||||
// }
|
||||
*new_prv_p = BKE_previewimg_copy(*old_prv_p);
|
||||
new_id->icon_id = (*new_prv_p)->icon_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
PreviewImage **BKE_previewimg_id_get_p(ID *id)
|
||||
{
|
||||
switch (GS(id->name)) {
|
||||
|
||||
@@ -459,7 +459,7 @@ Image *BKE_image_copy(Main *bmain, Image *ima)
|
||||
nima->stereo3d_format = MEM_dupallocN(ima->stereo3d_format);
|
||||
BLI_duplicatelist(&nima->views, &ima->views);
|
||||
|
||||
nima->preview = BKE_previewimg_copy(ima->preview);
|
||||
BKE_previewimg_id_copy(&nima->id, &ima->id);
|
||||
|
||||
if (ID_IS_LINKED_DATABLOCK(ima)) {
|
||||
BKE_id_expand_local(&nima->id);
|
||||
|
||||
@@ -135,8 +135,8 @@ Lamp *BKE_lamp_copy(Main *bmain, Lamp *la)
|
||||
|
||||
if (la->nodetree)
|
||||
lan->nodetree = ntreeCopyTree(bmain, la->nodetree);
|
||||
|
||||
lan->preview = BKE_previewimg_copy(la->preview);
|
||||
|
||||
BKE_previewimg_id_copy(&lan->id, &la->id);
|
||||
|
||||
if (ID_IS_LINKED_DATABLOCK(la)) {
|
||||
BKE_id_expand_local(&lan->id);
|
||||
|
||||
@@ -243,7 +243,7 @@ Material *BKE_material_copy(Main *bmain, Material *ma)
|
||||
man->nodetree = ntreeCopyTree(bmain, ma->nodetree);
|
||||
}
|
||||
|
||||
man->preview = BKE_previewimg_copy(ma->preview);
|
||||
BKE_previewimg_id_copy(&man->id, &ma->id);
|
||||
|
||||
BLI_listbase_clear(&man->gpumaterial);
|
||||
|
||||
|
||||
@@ -344,7 +344,7 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type)
|
||||
}
|
||||
}
|
||||
|
||||
scen->preview = BKE_previewimg_copy(sce->preview);
|
||||
BKE_previewimg_id_copy(&scen->id, &sce->id);
|
||||
|
||||
return scen;
|
||||
}
|
||||
|
||||
@@ -863,7 +863,6 @@ Tex *BKE_texture_copy(Main *bmain, Tex *tex)
|
||||
if (texn->pd) texn->pd = BKE_texture_pointdensity_copy(texn->pd);
|
||||
if (texn->vd) texn->vd = MEM_dupallocN(texn->vd);
|
||||
if (texn->ot) texn->ot = BKE_texture_ocean_copy(texn->ot);
|
||||
if (tex->preview) texn->preview = BKE_previewimg_copy(tex->preview);
|
||||
|
||||
if (tex->nodetree) {
|
||||
if (tex->nodetree->execdata) {
|
||||
@@ -871,8 +870,8 @@ Tex *BKE_texture_copy(Main *bmain, Tex *tex)
|
||||
}
|
||||
texn->nodetree = ntreeCopyTree(bmain, tex->nodetree);
|
||||
}
|
||||
|
||||
texn->preview = BKE_previewimg_copy(tex->preview);
|
||||
|
||||
BKE_previewimg_id_copy(&texn->id, &tex->id);
|
||||
|
||||
if (ID_IS_LINKED_DATABLOCK(tex)) {
|
||||
BKE_id_expand_local(&texn->id);
|
||||
|
||||
@@ -138,7 +138,7 @@ World *BKE_world_copy(Main *bmain, World *wrld)
|
||||
wrldn->nodetree = ntreeCopyTree(bmain, wrld->nodetree);
|
||||
}
|
||||
|
||||
wrldn->preview = BKE_previewimg_copy(wrld->preview);
|
||||
BKE_previewimg_id_copy(&wrldn->id, &wrld->id);
|
||||
|
||||
BLI_listbase_clear(&wrldn->gpumaterial);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user