Commit 02f94bab authored by AlicVB's avatar AlicVB Committed by AlicVB

masks: fix some leaks

parent 6dadfb48
......@@ -1344,6 +1344,7 @@ void dt_iop_gui_cleanup_blending(dt_iop_module_t *module)
g_list_free(bd->masks_combine);
g_list_free(bd->masks_invert);
g_list_free_full(bd->blend_modes_all, g_free);
free(bd->masks_combo_ids);
memset(module->blend_data, 0, sizeof(dt_iop_gui_blend_data_t));
......
......@@ -484,7 +484,6 @@ void dt_dev_load_image(dt_develop_t *dev, const uint32_t imgid)
dev->iop = dt_iop_load_modules(dev);
dt_masks_read_forms(dev);
dev->form_visible = NULL;
dt_dev_read_history(dev);
......
......@@ -275,7 +275,6 @@ void dt_masks_update_image(dt_develop_t *dev);
void dt_masks_cleanup_unused(dt_develop_t *dev);
/** function used to manipulate forms for masks */
void dt_masks_init_form_gui(dt_develop_t *dev);
void dt_masks_change_form_gui(dt_masks_form_t *newform);
void dt_masks_clear_form_gui(dt_develop_t *dev);
void dt_masks_reset_form_gui(void);
......
......@@ -1347,8 +1347,6 @@ static int dt_brush_events_button_pressed(struct dt_iop_module_t *module, float
gui->guipoints = NULL;
gui->guipoints_payload = NULL;
gui->guipoints_count = 0;
darktable.develop->form_visible = NULL;
dt_masks_clear_form_gui(darktable.develop);
dt_masks_set_edit_mode(module, DT_MASKS_EDIT_FULL);
dt_masks_iop_update(module);
dt_control_queue_redraw_center();
......@@ -1365,9 +1363,9 @@ static int dt_brush_events_button_pressed(struct dt_iop_module_t *module, float
dt_masks_clear_form_gui(darktable.develop);
// we hide the form
if(!(darktable.develop->form_visible->type & DT_MASKS_GROUP))
darktable.develop->form_visible = NULL;
dt_masks_change_form_gui(NULL);
else if(g_list_length(darktable.develop->form_visible->points) < 2)
darktable.develop->form_visible = NULL;
dt_masks_change_form_gui(NULL);
else
{
GList *forms = g_list_first(darktable.develop->form_visible->points);
......@@ -1378,6 +1376,7 @@ static int dt_brush_events_button_pressed(struct dt_iop_module_t *module, float
{
darktable.develop->form_visible->points
= g_list_remove(darktable.develop->form_visible->points, gpt);
free(gpt);
break;
}
forms = g_list_next(forms);
......@@ -1390,7 +1389,10 @@ static int dt_brush_events_button_pressed(struct dt_iop_module_t *module, float
dt_control_queue_redraw_center();
return 1;
}
form->points = g_list_delete_link(form->points, g_list_nth(form->points, gui->point_selected));
dt_masks_point_brush_t *point
= (dt_masks_point_brush_t *)g_list_nth_data(form->points, gui->point_selected);
form->points = g_list_remove(form->points, point);
free(point);
gui->point_selected = -1;
_brush_init_ctrl_points(form);
......@@ -1428,9 +1430,9 @@ static int dt_brush_events_button_pressed(struct dt_iop_module_t *module, float
dt_masks_clear_form_gui(darktable.develop);
// we hide the form
if(!(darktable.develop->form_visible->type & DT_MASKS_GROUP))
darktable.develop->form_visible = NULL;
dt_masks_change_form_gui(NULL);
else if(g_list_length(darktable.develop->form_visible->points) < 2)
darktable.develop->form_visible = NULL;
dt_masks_change_form_gui(NULL);
else
{
GList *forms = g_list_first(darktable.develop->form_visible->points);
......@@ -1441,6 +1443,7 @@ static int dt_brush_events_button_pressed(struct dt_iop_module_t *module, float
{
darktable.develop->form_visible->points
= g_list_remove(darktable.develop->form_visible->points, gpt);
free(gpt);
break;
}
forms = g_list_next(forms);
......@@ -1595,8 +1598,7 @@ static int dt_brush_events_button_released(struct dt_iop_module_t *module, float
// we remove the form
dt_masks_free_form(form);
darktable.develop->form_visible = NULL;
dt_masks_clear_form_gui(darktable.develop);
dt_masks_change_form_gui(NULL);
}
dt_control_queue_redraw_center();
......
......@@ -150,8 +150,6 @@ static int dt_circle_events_button_pressed(struct dt_iop_module_t *module, float
}
else if(gui->creation && (which == 3))
{
darktable.develop->form_visible = NULL;
dt_masks_clear_form_gui(darktable.develop);
dt_masks_set_edit_mode(module, DT_MASKS_EDIT_FULL);
dt_masks_iop_update(module);
dt_control_queue_redraw_center();
......@@ -251,9 +249,9 @@ static int dt_circle_events_button_released(struct dt_iop_module_t *module, floa
dt_masks_clear_form_gui(darktable.develop);
// we hide the form
if(!(darktable.develop->form_visible->type & DT_MASKS_GROUP))
darktable.develop->form_visible = NULL;
dt_masks_change_form_gui(NULL);
else if(g_list_length(darktable.develop->form_visible->points) < 2)
darktable.develop->form_visible = NULL;
dt_masks_change_form_gui(NULL);
else
{
GList *forms = g_list_first(darktable.develop->form_visible->points);
......@@ -264,6 +262,7 @@ static int dt_circle_events_button_released(struct dt_iop_module_t *module, floa
{
darktable.develop->form_visible->points
= g_list_remove(darktable.develop->form_visible->points, gpt);
free(gpt);
break;
}
forms = g_list_next(forms);
......
......@@ -314,8 +314,6 @@ static int dt_ellipse_events_button_pressed(struct dt_iop_module_t *module, floa
}
else if(gui->creation && (which == 3))
{
darktable.develop->form_visible = NULL;
dt_masks_clear_form_gui(darktable.develop);
dt_masks_set_edit_mode(module, DT_MASKS_EDIT_FULL);
dt_masks_iop_update(module);
dt_control_queue_redraw_center();
......@@ -432,9 +430,9 @@ static int dt_ellipse_events_button_released(struct dt_iop_module_t *module, flo
dt_masks_clear_form_gui(darktable.develop);
// we hide the form
if(!(darktable.develop->form_visible->type & DT_MASKS_GROUP))
darktable.develop->form_visible = NULL;
dt_masks_change_form_gui(NULL);
else if(g_list_length(darktable.develop->form_visible->points) < 2)
darktable.develop->form_visible = NULL;
dt_masks_change_form_gui(NULL);
else
{
GList *forms = g_list_first(darktable.develop->form_visible->points);
......@@ -445,6 +443,7 @@ static int dt_ellipse_events_button_released(struct dt_iop_module_t *module, flo
{
darktable.develop->form_visible->points
= g_list_remove(darktable.develop->form_visible->points, gpt);
free(gpt);
break;
}
forms = g_list_next(forms);
......
......@@ -136,8 +136,6 @@ static int dt_gradient_events_button_pressed(struct dt_iop_module_t *module, flo
}
else if(gui->creation && (which == 3))
{
darktable.develop->form_visible = NULL;
dt_masks_clear_form_gui(darktable.develop);
dt_masks_set_edit_mode(module, DT_MASKS_EDIT_FULL);
dt_masks_iop_update(module);
dt_control_queue_redraw_center();
......@@ -202,9 +200,9 @@ static int dt_gradient_events_button_released(struct dt_iop_module_t *module, fl
dt_masks_clear_form_gui(darktable.develop);
// we hide the form
if(!(darktable.develop->form_visible->type & DT_MASKS_GROUP))
darktable.develop->form_visible = NULL;
dt_masks_change_form_gui(NULL);
else if(g_list_length(darktable.develop->form_visible->points) < 2)
darktable.develop->form_visible = NULL;
dt_masks_change_form_gui(NULL);
else
{
GList *forms = g_list_first(darktable.develop->form_visible->points);
......@@ -215,6 +213,7 @@ static int dt_gradient_events_button_released(struct dt_iop_module_t *module, fl
{
darktable.develop->form_visible->points
= g_list_remove(darktable.develop->form_visible->points, gpt);
free(gpt);
break;
}
forms = g_list_next(forms);
......
......@@ -1349,6 +1349,7 @@ void dt_masks_events_post_expose(struct dt_iop_module_t *module, cairo_t *cr, in
void dt_masks_clear_form_gui(dt_develop_t *dev)
{
if(!dev->form_gui) return;
g_list_free_full(dev->form_gui->points, dt_masks_form_gui_points_free);
dev->form_gui->points = NULL;
dt_masks_dynbuf_free(dev->form_gui->guipoints);
......@@ -1374,27 +1375,21 @@ void dt_masks_clear_form_gui(dt_develop_t *dev)
dev->form_gui->group_edited = -1;
dev->form_gui->group_selected = -1;
}
void dt_masks_init_form_gui(dt_develop_t *dev)
{
dt_masks_clear_form_gui(dev);
dev->form_gui->edit_mode = DT_MASKS_EDIT_OFF;
dev->form_gui->guipoints = NULL;
dev->form_gui->guipoints_payload = NULL;
dev->form_gui->guipoints_count = 0;
}
void dt_masks_change_form_gui(dt_masks_form_t *newform)
{
dt_masks_clear_form_gui(darktable.develop);
// free the actual mask form if it's id is 0 (temp mask)
if(darktable.develop->form_visible && darktable.develop->form_visible->formid == 0)
dt_masks_free_form(darktable.develop->form_visible);
darktable.develop->form_visible = newform;
}
void dt_masks_reset_form_gui(void)
{
darktable.develop->form_visible = NULL;
dt_masks_clear_form_gui(darktable.develop);
dt_masks_change_form_gui(NULL);
dt_iop_module_t *m = darktable.develop->gui_module;
if(m && (m->flags() & IOP_FLAGS_SUPPORTS_BLENDING) && !(m->flags() & IOP_FLAGS_NO_MASKS))
{
......@@ -1884,11 +1879,11 @@ void dt_masks_form_remove(struct dt_iop_module_t *module, dt_masks_form_t *grp,
GList *forms = g_list_first(darktable.develop->forms);
while(forms)
{
dt_masks_form_t *form = (dt_masks_form_t *)forms->data;
if(form->formid == id)
dt_masks_form_t *f = (dt_masks_form_t *)forms->data;
if(f->formid == id)
{
darktable.develop->forms = g_list_remove(darktable.develop->forms, form);
dt_masks_free_form(form);
darktable.develop->forms = g_list_remove(darktable.develop->forms, f);
dt_masks_free_form(f);
dt_masks_write_forms(darktable.develop);
break;
}
......
......@@ -953,8 +953,6 @@ static int dt_path_events_button_pressed(struct dt_iop_module_t *module, float p
{
// we remove the form
dt_masks_free_form(form);
darktable.develop->form_visible = NULL;
dt_masks_clear_form_gui(darktable.develop);
dt_masks_set_edit_mode(module, DT_MASKS_EDIT_FULL);
dt_masks_iop_update(module);
dt_control_queue_redraw_center();
......@@ -1177,9 +1175,9 @@ static int dt_path_events_button_pressed(struct dt_iop_module_t *module, float p
dt_masks_clear_form_gui(darktable.develop);
// we hide the form
if(!(darktable.develop->form_visible->type & DT_MASKS_GROUP))
darktable.develop->form_visible = NULL;
dt_masks_change_form_gui(NULL);
else if(g_list_length(darktable.develop->form_visible->points) < 2)
darktable.develop->form_visible = NULL;
dt_masks_change_form_gui(NULL);
else
{
GList *forms = g_list_first(darktable.develop->form_visible->points);
......@@ -1190,6 +1188,7 @@ static int dt_path_events_button_pressed(struct dt_iop_module_t *module, float p
{
darktable.develop->form_visible->points
= g_list_remove(darktable.develop->form_visible->points, gpt);
free(gpt);
break;
}
forms = g_list_next(forms);
......@@ -1202,7 +1201,11 @@ static int dt_path_events_button_pressed(struct dt_iop_module_t *module, float p
dt_control_queue_redraw_center();
return 1;
}
form->points = g_list_delete_link(form->points, g_list_nth(form->points, gui->point_selected));
dt_masks_point_path_t *point
= (dt_masks_point_path_t *)g_list_nth_data(form->points, gui->point_selected);
form->points = g_list_remove(form->points, point);
free(point);
// form->points = g_list_delete_link(form->points, g_list_nth(form->points, gui->point_selected));
gui->point_selected = -1;
_path_init_ctrl_points(form);
......@@ -1242,9 +1245,9 @@ static int dt_path_events_button_pressed(struct dt_iop_module_t *module, float p
dt_masks_clear_form_gui(darktable.develop);
// we hide the form
if(!(darktable.develop->form_visible->type & DT_MASKS_GROUP))
darktable.develop->form_visible = NULL;
dt_masks_change_form_gui(NULL);
else if(g_list_length(darktable.develop->form_visible->points) < 2)
darktable.develop->form_visible = NULL;
dt_masks_change_form_gui(NULL);
else
{
GList *forms = g_list_first(darktable.develop->form_visible->points);
......@@ -1255,6 +1258,7 @@ static int dt_path_events_button_pressed(struct dt_iop_module_t *module, float p
{
darktable.develop->form_visible->points
= g_list_remove(darktable.develop->form_visible->points, gpt);
free(gpt);
break;
}
forms = g_list_next(forms);
......
......@@ -117,8 +117,6 @@ static void _bt_add_circle(GtkWidget *widget, GdkEventButton *event, dt_lib_modu
if(event->button == 1)
{
// we unset the creation mode
dt_masks_form_t *form = darktable.develop->form_visible;
if(form) dt_masks_free_form(form);
dt_masks_change_form_gui(NULL);
_lib_masks_inactivate_icons(self);
_tree_add_circle(NULL, NULL);
......@@ -141,8 +139,6 @@ static void _bt_add_ellipse(GtkWidget *widget, GdkEventButton *event, dt_lib_mod
if(event->button == 1)
{
// we unset the creation mode
dt_masks_form_t *form = darktable.develop->form_visible;
if(form) dt_masks_free_form(form);
dt_masks_change_form_gui(NULL);
_lib_masks_inactivate_icons(self);
_tree_add_ellipse(NULL, NULL);
......@@ -165,8 +161,6 @@ static void _bt_add_path(GtkWidget *widget, GdkEventButton *event, dt_lib_module
if(event->button == 1)
{
// we unset the creation mode
dt_masks_form_t *form = darktable.develop->form_visible;
if(form) dt_masks_free_form(form);
dt_masks_change_form_gui(NULL);
_lib_masks_inactivate_icons(self);
_tree_add_path(NULL, NULL);
......@@ -189,8 +183,6 @@ static void _bt_add_gradient(GtkWidget *widget, GdkEventButton *event, dt_lib_mo
if(event->button == 1)
{
// we unset the creation mode
dt_masks_form_t *form = darktable.develop->form_visible;
if(form) dt_masks_free_form(form);
dt_masks_change_form_gui(NULL);
_lib_masks_inactivate_icons(self);
_tree_add_gradient(NULL, NULL);
......@@ -213,8 +205,6 @@ static void _bt_add_brush(GtkWidget *widget, GdkEventButton *event, dt_lib_modul
if(event->button == 1)
{
// we unset the creation mode
dt_masks_form_t *form = darktable.develop->form_visible;
if(form) dt_masks_free_form(form);
dt_masks_change_form_gui(NULL);
_lib_masks_inactivate_icons(self);
_tree_add_brush(NULL, NULL);
......@@ -662,8 +652,7 @@ static void _tree_moveup(GtkButton *button, dt_lib_module_t *self)
dt_lib_masks_t *lm = (dt_lib_masks_t *)self->data;
// we first discard all visible shapes
dt_masks_clear_form_gui(darktable.develop);
darktable.develop->form_visible = NULL;
dt_masks_change_form_gui(NULL);
// now we go through all selected nodes
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(lm->treeview));
......@@ -703,8 +692,7 @@ static void _tree_movedown(GtkButton *button, dt_lib_module_t *self)
dt_lib_masks_t *lm = (dt_lib_masks_t *)self->data;
// we first discard all visible shapes
dt_masks_clear_form_gui(darktable.develop);
darktable.develop->form_visible = NULL;
dt_masks_change_form_gui(NULL);
// now we go through all selected nodes
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(lm->treeview));
......@@ -743,8 +731,7 @@ static void _tree_delete_shape(GtkButton *button, dt_lib_module_t *self)
dt_lib_masks_t *lm = (dt_lib_masks_t *)self->data;
// we first discard all visible shapes
dt_masks_clear_form_gui(darktable.develop);
darktable.develop->form_visible = NULL;
dt_masks_change_form_gui(NULL);
// now we go through all selected nodes
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(lm->treeview));
......@@ -859,8 +846,7 @@ static void _tree_selection_change(GtkTreeSelection *selection, dt_lib_masks_t *
int nb = gtk_tree_selection_count_selected_rows(selection);
if(nb == 0)
{
dt_masks_clear_form_gui(darktable.develop);
darktable.develop->form_visible = NULL;
dt_masks_change_form_gui(NULL);
dt_control_queue_redraw_center();
return;
}
......@@ -919,10 +905,10 @@ static void _tree_selection_change(GtkTreeSelection *selection, dt_lib_masks_t *
items = g_list_next(items);
}
dt_masks_form_t *grp2 = dt_masks_create(DT_MASKS_GROUP);
grp2->formid = 0;
dt_masks_group_ungroup(grp2, grp);
free(grp);
dt_masks_clear_form_gui(darktable.develop);
darktable.develop->form_visible = grp2;
dt_masks_free_form(grp);
dt_masks_change_form_gui(grp2);
darktable.develop->form_gui->edit_mode = DT_MASKS_EDIT_FULL;
dt_control_queue_redraw_center();
}
......
......@@ -552,10 +552,7 @@ static void dt_dev_change_image(dt_develop_t *dev, const uint32_t imgid)
{
dev->form_gui = (dt_masks_form_gui_t *)calloc(1, sizeof(dt_masks_form_gui_t));
}
dt_masks_init_form_gui(dev);
dev->form_visible = NULL;
dev->form_gui->pipe_hash = 0;
dev->form_gui->formid = 0;
dt_masks_change_form_gui(NULL);
select_this_image(imgid);
......@@ -1629,8 +1626,7 @@ void enter(dt_view_t *self)
{
dev->form_gui = (dt_masks_form_gui_t *)calloc(1, sizeof(dt_masks_form_gui_t));
}
dt_masks_init_form_gui(dev);
dev->form_visible = NULL;
dt_masks_change_form_gui(NULL);
dev->form_gui->pipe_hash = 0;
dev->form_gui->formid = 0;
dev->gui_leaving = 0;
......@@ -1813,7 +1809,7 @@ void leave(dt_view_t *self)
dt_masks_clear_form_gui(dev);
free(dev->form_gui);
dev->form_gui = NULL;
dev->form_visible = NULL;
dt_masks_change_form_gui(NULL);
}
// take care of the overexposed window
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment