Cleanup: deduplicate free code

It is more appropriate that `depths` is freed in `ED_view3d_depths_free`.
This commit is contained in:
2021-06-22 08:12:59 -03:00
parent 3f1111b2a8
commit ab063db34d
5 changed files with 15 additions and 13 deletions

View File

@@ -624,7 +624,6 @@ static void curve_draw_exit(wmOperator *op)
if (cdd->depths) { if (cdd->depths) {
ED_view3d_depths_free(cdd->depths); ED_view3d_depths_free(cdd->depths);
MEM_freeN(cdd->depths);
} }
MEM_freeN(cdd); MEM_freeN(cdd);
op->customdata = NULL; op->customdata = NULL;

View File

@@ -1687,7 +1687,6 @@ static void object_transform_axis_target_free_data(wmOperator *op)
#ifdef USE_RENDER_OVERRIDE #ifdef USE_RENDER_OVERRIDE
if (xfd->depths) { if (xfd->depths) {
ED_view3d_depths_free(xfd->depths); ED_view3d_depths_free(xfd->depths);
MEM_freeN(xfd->depths);
} }
#endif #endif

View File

@@ -525,14 +525,12 @@ static void PE_set_view3d_data(bContext *C, PEData *data)
ED_view3d_viewcontext_init(C, &data->vc, data->depsgraph); ED_view3d_viewcontext_init(C, &data->vc, data->depsgraph);
if (!XRAY_ENABLED(data->vc.v3d)) { if (!XRAY_ENABLED(data->vc.v3d)) {
if (!(data->vc.v3d->runtime.flag & V3D_RUNTIME_DEPTHBUF_OVERRIDDEN)) { ED_view3d_depth_override(data->depsgraph,
ED_view3d_depth_override(data->depsgraph, data->vc.region,
data->vc.region, data->vc.v3d,
data->vc.v3d, data->vc.obact,
data->vc.obact, V3D_DEPTH_OBJECT_ONLY,
V3D_DEPTH_OBJECT_ONLY, &data->depths);
&data->depths);
}
} }
} }
@@ -577,7 +575,6 @@ static void PE_data_free(PEData *data)
PE_free_shape_tree(data); PE_free_shape_tree(data);
if (data->depths) { if (data->depths) {
ED_view3d_depths_free(data->depths); ED_view3d_depths_free(data->depths);
MEM_freeN(data->depths);
data->depths = NULL; data->depths = NULL;
} }
} }

View File

@@ -2322,7 +2322,10 @@ void ED_view3d_depth_override(Depsgraph *depsgraph,
ViewDepths **r_depths) ViewDepths **r_depths)
{ {
if (v3d->runtime.flag & V3D_RUNTIME_DEPTHBUF_OVERRIDDEN) { if (v3d->runtime.flag & V3D_RUNTIME_DEPTHBUF_OVERRIDDEN) {
return; /* Force redraw if `r_depths` is required. */
if (!r_depths || *r_depths != NULL) {
return;
}
} }
struct bThemeState theme_state; struct bThemeState theme_state;
Scene *scene = DEG_get_evaluated_scene(depsgraph); Scene *scene = DEG_get_evaluated_scene(depsgraph);
@@ -2365,6 +2368,9 @@ void ED_view3d_depth_override(Depsgraph *depsgraph,
} }
if (r_depths) { if (r_depths) {
if (*r_depths) {
ED_view3d_depths_free(*r_depths);
}
*r_depths = view3d_depths_create(region); *r_depths = view3d_depths_create(region);
} }
} }
@@ -2384,6 +2390,7 @@ void ED_view3d_depths_free(ViewDepths *depths)
if (depths->depths) { if (depths->depths) {
MEM_freeN(depths->depths); MEM_freeN(depths->depths);
} }
MEM_freeN(depths);
} }
/** \} */ /** \} */

View File

@@ -1019,7 +1019,7 @@ static float view_autodist_depth_margin(ARegion *region, const int mval[2], int
ViewDepths depth_temp = {0}; ViewDepths depth_temp = {0};
view3d_depths_rect_create(region, &rect, &depth_temp); view3d_depths_rect_create(region, &rect, &depth_temp);
float depth_close = view3d_depth_near(&depth_temp); float depth_close = view3d_depth_near(&depth_temp);
ED_view3d_depths_free(&depth_temp); MEM_SAFE_FREE(depth_temp.depths);
return depth_close; return depth_close;
} }