Depsgraph: Fix copy-on-write assert when freeing Freestyle config

We were bumping user count when duplicating viewlayer and its freestyleconfig
depending on the flag, however when freeing we were always decreasing user
count.

This fixes this and get rid of the assert when running:
`--factory-startup --enable-copy-on-write`

And closing Blender.
This commit is contained in:
Dalai Felinto 2017-12-26 13:31:45 -02:00
parent fe1e2c2f89
commit bd80ace2da
Notes: blender-bot 2023-02-14 06:18:27 +01:00
Referenced by issue #53647, 2.8 blender exit after particular event using short key
Referenced by issue #53646, 2.8 multiple crashes in auto UVs generation
6 changed files with 20 additions and 10 deletions

View File

@ -49,7 +49,7 @@ typedef struct FreestyleModuleSettings FreestyleModuleSettings;
/* FreestyleConfig */
void BKE_freestyle_config_init(FreestyleConfig *config);
void BKE_freestyle_config_free(FreestyleConfig *config);
void BKE_freestyle_config_free(FreestyleConfig *config, const bool do_id_user);
void BKE_freestyle_config_copy(FreestyleConfig *new_config, FreestyleConfig *config, const int flag);
/* FreestyleConfig.modules */

View File

@ -66,6 +66,7 @@ struct ViewLayer *BKE_view_layer_group_add(struct Group *group);
struct ViewLayer *BKE_view_layer_context_active_PLACEHOLDER(const struct Scene *scene);
void BKE_view_layer_free(struct ViewLayer *view_layer);
void BKE_view_layer_free_ex(struct ViewLayer *view_layer, const bool do_id_user);
void BKE_view_layer_selected_objects_tag(struct ViewLayer *view_layer, const int tag);

View File

@ -61,17 +61,21 @@ void BKE_freestyle_config_init(FreestyleConfig *config)
BLI_listbase_clear(&config->linesets);
}
void BKE_freestyle_config_free(FreestyleConfig *config)
void BKE_freestyle_config_free(FreestyleConfig *config, const bool do_id_user)
{
FreestyleLineSet *lineset;
for (lineset = (FreestyleLineSet *)config->linesets.first; lineset; lineset = lineset->next) {
if (lineset->group) {
id_us_min(&lineset->group->id);
if (do_id_user) {
id_us_min(&lineset->group->id);
}
lineset->group = NULL;
}
if (lineset->linestyle) {
id_us_min(&lineset->linestyle->id);
if (do_id_user) {
id_us_min(&lineset->linestyle->id);
}
lineset->linestyle = NULL;
}
}

View File

@ -163,10 +163,15 @@ ViewLayer *BKE_view_layer_group_add(Group *group)
return view_layer;
}
void BKE_view_layer_free(ViewLayer *view_layer)
{
BKE_view_layer_free_ex(view_layer, true);
}
/**
* Free (or release) any data used by this ViewLayer.
*/
void BKE_view_layer_free(ViewLayer *view_layer)
void BKE_view_layer_free_ex(ViewLayer *view_layer, const bool do_id_user)
{
view_layer->basact = NULL;
@ -205,7 +210,7 @@ void BKE_view_layer_free(ViewLayer *view_layer)
MEM_SAFE_FREE(view_layer->stats);
BKE_freestyle_config_free(&view_layer->freestyle_config);
BKE_freestyle_config_free(&view_layer->freestyle_config, do_id_user);
if (view_layer->id_properties) {
IDP_FreeProperty(view_layer->id_properties);

View File

@ -540,7 +540,7 @@ void BKE_scene_free_ex(Scene *sce, const bool do_id_user)
view_layer_next = view_layer->next;
BLI_remlink(&sce->view_layers, view_layer);
BKE_view_layer_free(view_layer);
BKE_view_layer_free_ex(view_layer, do_id_user);
}
/* Master Collection */

View File

@ -352,7 +352,7 @@ void do_versions_after_linking_280(Main *main)
view_layer->pass_xor = srl->pass_xor;
view_layer->pass_alpha_threshold = srl->pass_alpha_threshold;
BKE_freestyle_config_free(&view_layer->freestyle_config);
BKE_freestyle_config_free(&view_layer->freestyle_config, true);
view_layer->freestyle_config = srl->freestyleConfig;
view_layer->id_properties = srl->prop;
@ -425,7 +425,7 @@ void do_versions_after_linking_280(Main *main)
IDP_FreeProperty(srl->prop);
MEM_freeN(srl->prop);
}
BKE_freestyle_config_free(&srl->freestyleConfig);
BKE_freestyle_config_free(&srl->freestyleConfig, true);
}
}
BLI_freelistN(&scene->r.layers);
@ -540,7 +540,7 @@ void do_versions_after_linking_280(Main *main)
IDP_FreeProperty(srl->prop);
MEM_freeN(srl->prop);
}
BKE_freestyle_config_free(&srl->freestyleConfig);
BKE_freestyle_config_free(&srl->freestyleConfig, true);
}
BLI_freelistN(&scene->r.layers);
}