Commit fc4add7c authored by Michael Natterer's avatar Michael Natterer

Issue #1538 - Crash when adding file to already opened image and...

...closing this image while the file is being loaded

Ref the image around all calls to file_open_layers() and
gimp_image_add_layers() so it stays around even if the user closes the
display in the meantime.
parent 24233bc4
...@@ -128,6 +128,9 @@ file_open_dialog_response (GtkWidget *dialog, ...@@ -128,6 +128,9 @@ file_open_dialog_response (GtkWidget *dialog,
if (! open_dialog->open_as_layers) if (! open_dialog->open_as_layers)
gtk_window_set_transient_for (GTK_WINDOW (dialog), NULL); gtk_window_set_transient_for (GTK_WINDOW (dialog), NULL);
if (file_dialog->image)
g_object_ref (file_dialog->image);
for (list = files; list; list = g_slist_next (list)) for (list = files; list; list = g_slist_next (list))
{ {
GFile *file = list->data; GFile *file = list->data;
...@@ -142,7 +145,10 @@ file_open_dialog_response (GtkWidget *dialog, ...@@ -142,7 +145,10 @@ file_open_dialog_response (GtkWidget *dialog,
file_dialog->file_proc); file_dialog->file_proc);
if (file_dialog->image) if (file_dialog->image)
success = TRUE; {
g_object_ref (file_dialog->image);
success = TRUE;
}
} }
else if (file_open_dialog_open_layers (dialog, else if (file_open_dialog_open_layers (dialog,
file_dialog->image, file_dialog->image,
...@@ -174,13 +180,21 @@ file_open_dialog_response (GtkWidget *dialog, ...@@ -174,13 +180,21 @@ file_open_dialog_response (GtkWidget *dialog,
if (success) if (success)
{ {
if (open_dialog->open_as_layers && file_dialog->image) if (file_dialog->image)
gimp_image_flush (file_dialog->image); {
if (open_dialog->open_as_layers)
gimp_image_flush (file_dialog->image);
g_object_unref (file_dialog->image);
}
gtk_widget_destroy (dialog); gtk_widget_destroy (dialog);
} }
else else
{ {
if (file_dialog->image)
g_object_unref (file_dialog->image);
gimp_file_dialog_set_sensitive (file_dialog, TRUE); gimp_file_dialog_set_sensitive (file_dialog, TRUE);
} }
......
...@@ -516,12 +516,11 @@ gimp_display_shell_drop_uri_list (GtkWidget *widget, ...@@ -516,12 +516,11 @@ gimp_display_shell_drop_uri_list (GtkWidget *widget,
GList *list; GList *list;
gboolean open_as_layers; gboolean open_as_layers;
/* If the app is already being torn down, shell->display might be NULL here. /* If the app is already being torn down, shell->display might be
* Play it safe. */ * NULL here. Play it safe.
*/
if (! shell->display) if (! shell->display)
{ return;
return;
}
image = gimp_display_get_image (shell->display); image = gimp_display_get_image (shell->display);
context = gimp_get_user_context (shell->display->gimp); context = gimp_get_user_context (shell->display->gimp);
...@@ -530,6 +529,9 @@ gimp_display_shell_drop_uri_list (GtkWidget *widget, ...@@ -530,6 +529,9 @@ gimp_display_shell_drop_uri_list (GtkWidget *widget,
open_as_layers = (image != NULL); open_as_layers = (image != NULL);
if (image)
g_object_ref (image);
for (list = uri_list; list; list = g_list_next (list)) for (list = uri_list; list; list = g_list_next (list))
{ {
GFile *file = g_file_new_for_uri (list->data); GFile *file = g_file_new_for_uri (list->data);
...@@ -541,6 +543,7 @@ gimp_display_shell_drop_uri_list (GtkWidget *widget, ...@@ -541,6 +543,7 @@ gimp_display_shell_drop_uri_list (GtkWidget *widget,
{ {
/* It seems as if GIMP is being torn down for quitting. Bail out. */ /* It seems as if GIMP is being torn down for quitting. Bail out. */
g_object_unref (file); g_object_unref (file);
g_clear_object (&image);
return; return;
} }
...@@ -556,11 +559,14 @@ gimp_display_shell_drop_uri_list (GtkWidget *widget, ...@@ -556,11 +559,14 @@ gimp_display_shell_drop_uri_list (GtkWidget *widget,
if (new_layers) if (new_layers)
{ {
gint x, y; gint x = 0;
gint width, height; gint y = 0;
gint width = gimp_image_get_width (image);
gint height = gimp_image_get_height (image);
gimp_display_shell_untransform_viewport (shell, &x, &y, if (gimp_display_get_image (shell->display))
&width, &height); gimp_display_shell_untransform_viewport (shell, &x, &y,
&width, &height);
gimp_image_add_layers (image, new_layers, gimp_image_add_layers (image, new_layers,
GIMP_IMAGE_ACTIVE_PARENT, -1, GIMP_IMAGE_ACTIVE_PARENT, -1,
...@@ -597,13 +603,20 @@ gimp_display_shell_drop_uri_list (GtkWidget *widget, ...@@ -597,13 +603,20 @@ gimp_display_shell_drop_uri_list (GtkWidget *widget,
G_OBJECT (gimp_widget_get_monitor (widget)), G_OBJECT (gimp_widget_get_monitor (widget)),
&status, &error); &status, &error);
if (! image && status != GIMP_PDB_CANCEL) if (image)
warn = TRUE; {
g_object_ref (image);
}
else if (status != GIMP_PDB_CANCEL)
{
warn = TRUE;
}
} }
/* Something above might have run a few rounds of the main loop. Check /* Something above might have run a few rounds of the main loop. Check
* that shell->display is still there, otherwise ignore this as the app * that shell->display is still there, otherwise ignore this as the app
* is being torn down for quitting. */ * is being torn down for quitting.
*/
if (warn && shell->display) if (warn && shell->display)
{ {
gimp_message (shell->display->gimp, G_OBJECT (shell->display), gimp_message (shell->display->gimp, G_OBJECT (shell->display),
...@@ -618,6 +631,8 @@ gimp_display_shell_drop_uri_list (GtkWidget *widget, ...@@ -618,6 +631,8 @@ gimp_display_shell_drop_uri_list (GtkWidget *widget,
if (image) if (image)
gimp_display_shell_dnd_flush (shell, image); gimp_display_shell_dnd_flush (shell, image);
g_clear_object (&image);
} }
static void static void
......
...@@ -722,6 +722,8 @@ gimp_layer_tree_view_drop_uri_list (GimpContainerTreeView *view, ...@@ -722,6 +722,8 @@ gimp_layer_tree_view_drop_uri_list (GimpContainerTreeView *view,
drop_pos, drop_pos,
(GimpViewable **) &parent); (GimpViewable **) &parent);
g_object_ref (image);
for (list = uri_list; list; list = g_list_next (list)) for (list = uri_list; list; list = g_list_next (list))
{ {
const gchar *uri = list->data; const gchar *uri = list->data;
...@@ -761,6 +763,8 @@ gimp_layer_tree_view_drop_uri_list (GimpContainerTreeView *view, ...@@ -761,6 +763,8 @@ gimp_layer_tree_view_drop_uri_list (GimpContainerTreeView *view,
} }
gimp_image_flush (image); gimp_image_flush (image);
g_object_unref (image);
} }
static void static void
......
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