Fix: Properly free/allocate non-trivial shrinkwrap cache struct
Mistake in 0b80d5e755
Pull Request: https://projects.blender.org/blender/blender/pulls/120527
This commit is contained in:
@@ -98,18 +98,19 @@ void BKE_gpencil_cache_data_init(Depsgraph *depsgraph, Object *ob)
|
||||
}
|
||||
if (mmd->cache_data) {
|
||||
BKE_shrinkwrap_free_tree(mmd->cache_data);
|
||||
MEM_SAFE_FREE(mmd->cache_data);
|
||||
MEM_delete(mmd->cache_data);
|
||||
mmd->cache_data = nullptr;
|
||||
}
|
||||
Object *ob_target = DEG_get_evaluated_object(depsgraph, ob);
|
||||
Mesh *target = BKE_modifier_get_evaluated_mesh_from_evaluated_object(ob_target);
|
||||
mmd->cache_data = static_cast<ShrinkwrapTreeData *>(
|
||||
MEM_callocN(sizeof(ShrinkwrapTreeData), __func__));
|
||||
mmd->cache_data = MEM_new<ShrinkwrapTreeData>(__func__);
|
||||
if (BKE_shrinkwrap_init_tree(
|
||||
mmd->cache_data, target, mmd->shrink_type, mmd->shrink_mode, false))
|
||||
{
|
||||
}
|
||||
else {
|
||||
MEM_SAFE_FREE(mmd->cache_data);
|
||||
MEM_delete(mmd->cache_data);
|
||||
mmd->cache_data = nullptr;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -136,7 +137,8 @@ void BKE_gpencil_cache_data_clear(Object *ob)
|
||||
ShrinkwrapGpencilModifierData *mmd = (ShrinkwrapGpencilModifierData *)md;
|
||||
if ((mmd) && (mmd->cache_data)) {
|
||||
BKE_shrinkwrap_free_tree(mmd->cache_data);
|
||||
MEM_SAFE_FREE(mmd->cache_data);
|
||||
MEM_delete(mmd->cache_data);
|
||||
mmd->cache_data = nullptr;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -139,12 +139,12 @@ static void bake_modifier(Main * /*bmain*/,
|
||||
/* Recalculate shrinkwrap data. */
|
||||
if (mmd->cache_data) {
|
||||
BKE_shrinkwrap_free_tree(mmd->cache_data);
|
||||
MEM_SAFE_FREE(mmd->cache_data);
|
||||
MEM_delete(mmd->cache_data);
|
||||
mmd->cache_data = nullptr;
|
||||
}
|
||||
Object *ob_target = DEG_get_evaluated_object(depsgraph, mmd->target);
|
||||
Mesh *target = BKE_modifier_get_evaluated_mesh_from_evaluated_object(ob_target);
|
||||
mmd->cache_data = static_cast<ShrinkwrapTreeData *>(
|
||||
MEM_callocN(sizeof(ShrinkwrapTreeData), __func__));
|
||||
mmd->cache_data = MEM_new<ShrinkwrapTreeData>(__func__);
|
||||
if (BKE_shrinkwrap_init_tree(
|
||||
mmd->cache_data, target, mmd->shrink_type, mmd->shrink_mode, false))
|
||||
{
|
||||
@@ -157,7 +157,8 @@ static void bake_modifier(Main * /*bmain*/,
|
||||
/* Free data. */
|
||||
if (mmd->cache_data) {
|
||||
BKE_shrinkwrap_free_tree(mmd->cache_data);
|
||||
MEM_SAFE_FREE(mmd->cache_data);
|
||||
MEM_delete(mmd->cache_data);
|
||||
mmd->cache_data = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -172,7 +173,7 @@ static void free_data(GpencilModifierData *md)
|
||||
ShrinkwrapGpencilModifierData *mmd = (ShrinkwrapGpencilModifierData *)md;
|
||||
if (mmd->cache_data) {
|
||||
BKE_shrinkwrap_free_tree(mmd->cache_data);
|
||||
MEM_SAFE_FREE(mmd->cache_data);
|
||||
MEM_delete(mmd->cache_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ static void free_data(ModifierData *md)
|
||||
|
||||
if (smd->cache_data) {
|
||||
BKE_shrinkwrap_free_tree(smd->cache_data);
|
||||
MEM_SAFE_FREE(smd->cache_data);
|
||||
MEM_delete(smd->cache_data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,17 +196,18 @@ static void ensure_shrinkwrap_cache_data(GreasePencilShrinkwrapModifierData &smd
|
||||
{
|
||||
if (smd.cache_data) {
|
||||
BKE_shrinkwrap_free_tree(smd.cache_data);
|
||||
MEM_SAFE_FREE(smd.cache_data);
|
||||
MEM_delete(smd.cache_data);
|
||||
smd.cache_data = nullptr;
|
||||
}
|
||||
Object *target_ob = DEG_get_evaluated_object(ctx.depsgraph, smd.target);
|
||||
Mesh *target_mesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(target_ob);
|
||||
|
||||
smd.cache_data = static_cast<ShrinkwrapTreeData *>(
|
||||
MEM_callocN(sizeof(ShrinkwrapTreeData), __func__));
|
||||
smd.cache_data = MEM_new<ShrinkwrapTreeData>(__func__);
|
||||
const bool tree_ok = BKE_shrinkwrap_init_tree(
|
||||
smd.cache_data, target_mesh, smd.shrink_type, smd.shrink_mode, false);
|
||||
if (!tree_ok) {
|
||||
MEM_SAFE_FREE(smd.cache_data);
|
||||
MEM_delete(smd.cache_data);
|
||||
smd.cache_data = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user