From 1c71e30cd0349d452295f7d921280798627d3477 Mon Sep 17 00:00:00 2001 From: Alx Sa Date: Tue, 24 Jun 2025 14:38:20 +0000 Subject: [PATCH] widgets: Confirm image is indexed before setting entry It is possible to have an indexed image open in one tab, and RGB/grayscale images open in others. If you have the color editor open and swap between them, you'll receive a CRITICAL because the ColorMapEditor will always try to update a color entry even if the active image is not indexed. This patch adds checks to ensure you have the indexed image open before trying to update its color entry. --- app/widgets/gimpcolordialog.c | 20 ++++++++++++++------ app/widgets/gimpcolormapeditor.c | 3 ++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/widgets/gimpcolordialog.c b/app/widgets/gimpcolordialog.c index d3a89f25f9..8410040d00 100644 --- a/app/widgets/gimpcolordialog.c +++ b/app/widgets/gimpcolordialog.c @@ -386,9 +386,13 @@ gimp_color_dialog_response (GtkDialog *gtk_dialog, /* Restore old color for undo */ old_color = gimp_color_selection_get_old_color (GIMP_COLOR_SELECTION (dialog->selection)); - gimp_image_set_colormap_entry (image, col_index, old_color, FALSE); - gimp_image_set_colormap_entry (image, col_index, color, TRUE); - gimp_image_flush (image); + + if (gimp_image_get_base_type (image) == GIMP_INDEXED) + { + gimp_image_set_colormap_entry (image, col_index, old_color, FALSE); + gimp_image_set_colormap_entry (image, col_index, color, TRUE); + gimp_image_flush (image); + } gtk_stack_set_visible_child_name (GTK_STACK (dialog->stack), "colormap"); g_signal_emit (dialog, color_dialog_signals[UPDATE], 0, @@ -412,8 +416,11 @@ gimp_color_dialog_response (GtkDialog *gtk_dialog, { dialog->colormap_editing = FALSE; - gimp_image_set_colormap_entry (image, col_index, color, FALSE); - gimp_projection_flush (gimp_image_get_projection (image)); + if (gimp_image_get_base_type (image) == GIMP_INDEXED) + { + gimp_image_set_colormap_entry (image, col_index, color, FALSE); + gimp_projection_flush (gimp_image_get_projection (image)); + } gtk_stack_set_visible_child_name (GTK_STACK (dialog->stack), "colormap"); g_signal_emit (dialog, color_dialog_signals[UPDATE], 0, @@ -683,7 +690,8 @@ gimp_color_dialog_color_changed (GimpColorSelection *selection, g_object_unref (old_color); } - gimp_image_set_colormap_entry (image, col_index, color, push_undo); + if (gimp_image_get_base_type (image) == GIMP_INDEXED) + gimp_image_set_colormap_entry (image, col_index, color, push_undo); if (push_undo) gimp_image_flush (image); diff --git a/app/widgets/gimpcolormapeditor.c b/app/widgets/gimpcolormapeditor.c index 1fb1def4b1..c1950ebe3b 100644 --- a/app/widgets/gimpcolormapeditor.c +++ b/app/widgets/gimpcolormapeditor.c @@ -384,7 +384,8 @@ gimp_colormap_editor_color_update (GimpColorDialog *dialog, break; } - if (image) + if (image && + gimp_image_get_base_type (image) == GIMP_INDEXED) { gint col_index;