From 01b55aca07d51226f18a2a3a2901c4c41b67c269 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Sat, 23 Nov 2024 14:17:41 +0200 Subject: [PATCH] Fix crash when using indexed mode without a palette --- src/Classes/ImageExtended.gd | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Classes/ImageExtended.gd b/src/Classes/ImageExtended.gd index fac52e123..4b5ef9ea5 100644 --- a/src/Classes/ImageExtended.gd +++ b/src/Classes/ImageExtended.gd @@ -74,6 +74,8 @@ func select_palette(_name: String, convert_to_rgb := true) -> void: ## Updates [member palette] to contain the colors of [member current_palette]. func update_palette() -> void: + if not is_instance_valid(current_palette): + return if palette.size() != current_palette.colors_max: palette.resize(current_palette.colors_max) palette.fill(TRANSPARENT) @@ -83,9 +85,9 @@ func update_palette() -> void: ## Displays the actual RGBA values of each pixel in the image from indexed mode. func convert_indexed_to_rgb() -> void: - if not is_indexed: + if not is_indexed or not is_instance_valid(current_palette): return - var palette_image := Palettes.current_palette.convert_to_image(false) + var palette_image := current_palette.convert_to_image(false) var palette_texture := ImageTexture.create_from_image(palette_image) var shader_image_effect := ShaderImageEffect.new() var indices_texture := ImageTexture.create_from_image(indices_image) @@ -97,9 +99,9 @@ func convert_indexed_to_rgb() -> void: ## Automatically maps each color of the image's pixel to the closest color of the palette, ## by finding the palette color's index and storing it in [member indices_image]. func convert_rgb_to_indexed() -> void: - if not is_indexed: + if not is_indexed or not is_instance_valid(current_palette): return - var palette_image := Palettes.current_palette.convert_to_image(false) + var palette_image := current_palette.convert_to_image(false) var palette_texture := ImageTexture.create_from_image(palette_image) var params := { "palette_texture": palette_texture, "rgb_texture": ImageTexture.create_from_image(self)