1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

Fix crash when using indexed mode without a palette

This commit is contained in:
Emmanouil Papadeas 2024-11-23 14:17:41 +02:00
parent 5f53a3eb7b
commit 01b55aca07

View file

@ -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]. ## Updates [member palette] to contain the colors of [member current_palette].
func update_palette() -> void: func update_palette() -> void:
if not is_instance_valid(current_palette):
return
if palette.size() != current_palette.colors_max: if palette.size() != current_palette.colors_max:
palette.resize(current_palette.colors_max) palette.resize(current_palette.colors_max)
palette.fill(TRANSPARENT) 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. ## Displays the actual RGBA values of each pixel in the image from indexed mode.
func convert_indexed_to_rgb() -> void: func convert_indexed_to_rgb() -> void:
if not is_indexed: if not is_indexed or not is_instance_valid(current_palette):
return 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 palette_texture := ImageTexture.create_from_image(palette_image)
var shader_image_effect := ShaderImageEffect.new() var shader_image_effect := ShaderImageEffect.new()
var indices_texture := ImageTexture.create_from_image(indices_image) 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, ## 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]. ## by finding the palette color's index and storing it in [member indices_image].
func convert_rgb_to_indexed() -> void: func convert_rgb_to_indexed() -> void:
if not is_indexed: if not is_indexed or not is_instance_valid(current_palette):
return 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 palette_texture := ImageTexture.create_from_image(palette_image)
var params := { var params := {
"palette_texture": palette_texture, "rgb_texture": ImageTexture.create_from_image(self) "palette_texture": palette_texture, "rgb_texture": ImageTexture.create_from_image(self)