Issue #3070: CRITICAL when converting to Indexed image.

Revert the previous commit 786686a541 and comes up with a better fix.

Let's actually change the image base type and add its colormap as close
as possible without any GUI calls in-between. I also add an explicative
comment so that people are aware of this call proximity requirement to
avoid future problems when the code gets remixed.

It should be better than hacking around with exception in GUI code, and
should (hopefully) avoid other similar bugs.
This commit is contained in:
Jehan 2019-07-17 13:08:06 +02:00
parent 786686a541
commit 03f645cd2d
2 changed files with 17 additions and 21 deletions

View File

@ -810,14 +810,6 @@ gimp_image_convert_indexed (GimpImage *image,
/* Set the new base type */
old_type = gimp_image_get_base_type (image);
g_object_set (image, "base-type", GIMP_INDEXED, NULL);
/* when converting from GRAY, always convert to the new type's
* builtin profile
*/
if (old_type == GIMP_GRAY)
dest_profile = gimp_image_get_builtin_color_profile (image);
/* Build histogram if necessary. */
rgb_to_lab_fish = babl_fish (babl_format ("R'G'B' float"),
babl_format ("CIE Lab float"));
@ -950,6 +942,16 @@ gimp_image_convert_indexed (GimpImage *image,
if (quantobj->second_pass_init)
quantobj->second_pass_init (quantobj);
/* Set the base type just before we also set the colormap. In
* particular we must not let any GUI code in-between (like progress
* update) in order to avoid any context switch. Some various pieces
* of the code are relying on proper image state, and an indexed image
* without a colormap is not a proper state (it will also have neither
* babl format nor profile).
* See #3070.
*/
g_object_set (image, "base-type", GIMP_INDEXED, NULL);
/* Set the generated palette on the image, we need it to
* convert the layers. We optionally remove duplicate entries
* after the layer conversion.
@ -969,6 +971,12 @@ gimp_image_convert_indexed (GimpImage *image,
quantobj->actual_number_of_colors, TRUE);
}
/* when converting from GRAY, always convert to the new type's
* builtin profile
*/
if (old_type == GIMP_GRAY)
dest_profile = gimp_image_get_builtin_color_profile (image);
/* Convert all layers */
for (list = all_layers;
list;

View File

@ -81,28 +81,16 @@ static gboolean
gimp_display_shell_update_title_idle (gpointer data)
{
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data);
GimpImage *image;
shell->title_idle_id = 0;
image = gimp_display_get_image (shell->display);
if (image)
if (gimp_display_get_image (shell->display))
{
GimpDisplayConfig *config = shell->display->config;
gchar title[MAX_TITLE_BUF];
gchar status[MAX_TITLE_BUF];
gint len;
/* This is a ugly hack to prevent this function to be called while
* an image is being converted to indexed (which may happen as
* various context switch happen during progress update). In such
* edge case, we end up in an in-between time where the image is
* seamingly broken as it has no format (hence no profile either).
*/
if (gimp_image_get_base_type (image) == GIMP_INDEXED &&
! gimp_image_get_layer_format (image, FALSE))
return FALSE;
/* format the title */
len = gimp_display_shell_format_title (shell, title, sizeof (title),
config->image_title_format);