Fix T69789: Assert when create a new Full Copy scene base on 2D template.

Private ID data (nodetrees and scene collections...) need special care
and handling of their copy flags, and checks must be adapted too.

In that case, issue came from the fact that even though those IDs have
to be copied outside of bmain, we may still require usercount handling.

That commit also fixes a somewhat related issue - we cannot use the
non-id private data copying flag for private IDs copying, due to
difference in handling of usercount again.
This commit is contained in:
Bastien Montagne 2019-09-12 12:24:24 +02:00
parent 4df75063e1
commit 0137509476
7 changed files with 17 additions and 17 deletions

View file

@ -1411,14 +1411,21 @@ void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, int flag)
{
ID *new_id = *r_newid;
const bool is_private_id_data = (id->flag & LIB_PRIVATE_DATA) != 0;
BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) != 0 || bmain != NULL);
BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) != 0 || (flag & LIB_ID_CREATE_NO_ALLOCATE) == 0);
BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) == 0 || (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) != 0);
if (!is_private_id_data) {
/* When we are handling private ID data, we might still want to manage usercounts, even though
* that ID data-block is actually outside of Main... */
BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) == 0 ||
(flag & LIB_ID_CREATE_NO_USER_REFCOUNT) != 0);
}
/* Never implicitly copy shapekeys when generating temp data outside of Main database. */
BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) == 0 || (flag & LIB_ID_COPY_SHAPEKEY) == 0);
/* 'Private ID' data handling. */
if ((bmain != NULL) && (id->flag & LIB_PRIVATE_DATA) != 0) {
if ((bmain != NULL) && is_private_id_data) {
flag |= LIB_ID_CREATE_NO_MAIN;
}
@ -1467,7 +1474,8 @@ void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, int flag)
/* the duplicate should get a copy of the animdata */
if ((flag & LIB_ID_COPY_NO_ANIMDATA) == 0) {
BLI_assert((flag & LIB_ID_COPY_ACTIONS) == 0 || (flag & LIB_ID_CREATE_NO_MAIN) == 0);
BLI_assert((flag & LIB_ID_COPY_ACTIONS) == 0 || (flag & LIB_ID_CREATE_NO_MAIN) == 0 ||
is_private_id_data);
iat->adt = BKE_animdata_copy(bmain, iat->adt, flag);
}
else {

View file

@ -78,10 +78,8 @@ Light *BKE_light_add(Main *bmain, const char *name)
*/
void BKE_light_copy_data(Main *bmain, Light *la_dst, const Light *la_src, const int flag)
{
/* We never handle usercount here for own data. */
const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
/* We always need allocation of our private ID data. */
const int flag_private_id_data = flag_subdata & ~LIB_ID_CREATE_NO_ALLOCATE;
const int flag_private_id_data = flag & ~LIB_ID_CREATE_NO_ALLOCATE;
la_dst->curfalloff = BKE_curvemapping_copy(la_src->curfalloff);

View file

@ -144,7 +144,7 @@ void BKE_linestyle_copy_data(struct Main *bmain,
/* We never handle usercount here for own data. */
const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
/* We always need allocation of our private ID data. */
const int flag_private_id_data = flag_subdata & ~LIB_ID_CREATE_NO_ALLOCATE;
const int flag_private_id_data = flag & ~LIB_ID_CREATE_NO_ALLOCATE;
for (int a = 0; a < MAX_MTEX; a++) {
if (linestyle_src->mtex[a]) {

View file

@ -186,10 +186,8 @@ Material *BKE_material_add_gpencil(Main *bmain, const char *name)
*/
void BKE_material_copy_data(Main *bmain, Material *ma_dst, const Material *ma_src, const int flag)
{
/* We never handle usercount here for own data. */
const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
/* We always need allocation of our private ID data. */
const int flag_private_id_data = flag_subdata & ~LIB_ID_CREATE_NO_ALLOCATE;
const int flag_private_id_data = flag & ~LIB_ID_CREATE_NO_ALLOCATE;
if (ma_src->nodetree) {
BKE_id_copy_ex(bmain, (ID *)ma_src->nodetree, (ID **)&ma_dst->nodetree, flag_private_id_data);

View file

@ -242,7 +242,7 @@ void BKE_scene_copy_data(Main *bmain, Scene *sce_dst, const Scene *sce_src, cons
/* We never handle usercount here for own data. */
const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
/* We always need allocation of our private ID data. */
const int flag_private_id_data = flag_subdata & ~LIB_ID_CREATE_NO_ALLOCATE;
const int flag_private_id_data = flag & ~LIB_ID_CREATE_NO_ALLOCATE;
sce_dst->ed = NULL;
sce_dst->depsgraph_hash = NULL;

View file

@ -317,10 +317,8 @@ MTex *BKE_texture_mtex_add_id(ID *id, int slot)
*/
void BKE_texture_copy_data(Main *bmain, Tex *tex_dst, const Tex *tex_src, const int flag)
{
/* We never handle usercount here for own data. */
const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
/* We always need allocation of our private ID data. */
const int flag_private_id_data = flag_subdata & ~LIB_ID_CREATE_NO_ALLOCATE;
const int flag_private_id_data = flag & ~LIB_ID_CREATE_NO_ALLOCATE;
if (!BKE_texture_is_image_user(tex_src)) {
tex_dst->ima = NULL;

View file

@ -98,10 +98,8 @@ World *BKE_world_add(Main *bmain, const char *name)
*/
void BKE_world_copy_data(Main *bmain, World *wrld_dst, const World *wrld_src, const int flag)
{
/* We never handle usercount here for own data. */
const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
/* We always need allocation of our private ID data. */
const int flag_private_id_data = flag_subdata & ~LIB_ID_CREATE_NO_ALLOCATE;
const int flag_private_id_data = flag & ~LIB_ID_CREATE_NO_ALLOCATE;
if (wrld_src->nodetree) {
BKE_id_copy_ex(