Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error messages when creating Images from code #60126

Merged
merged 1 commit into from
May 16, 2022

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Apr 10, 2022

The rationale behind the expected number of bytes is now displayed in clear (width, height, format, number of mipmaps expected if any).

Requested by @2shady4u 🙂

Preview

Testing script
extends Node2D


func _ready():
	var image = Image.new()
	var data = PackedByteArray()
	image.create_from_data(512, 512, false, Image.FORMAT_RGB8, data)

	var image2 = Image.new()
	image2.create_from_data(320, 200, true, Image.FORMAT_L8, data)
	
	var image_small = Image.new()
	image_small.create_from_data(2, 2, true, Image.FORMAT_RGBE9995, data)

	var image_large = Image.new()
	image_large.create(16385, 1, false, Image.FORMAT_L8)
	
	var image_zero = Image.new()
	image_zero.create(0, 0, false, Image.FORMAT_L8)
	
	var image_invalid_format = Image.new()
	image_invalid_format.create(256, 256, false, 9999)

Before

ERROR: Expected data size of 786432 bytes in Image::create(), got instead 0 bytes.
   at: create (core/io/image.cpp:1980)
ERROR: Expected data size of 85318 bytes in Image::create(), got instead 0 bytes.
   at: create (core/io/image.cpp:1980)
ERROR: Expected data size of 20 bytes in Image::create(), got instead 0 bytes.
   at: create (core/io/image.cpp:1980)
ERROR: Image width must be greater than 0.
   at: create (core/io/image.cpp:1947)
ERROR: Image format out of range, please see Image's Format enum.
   at: create (core/io/image.cpp:1952)

After

ERROR: Expected Image data size of 512x512x3 (without mipmaps) = 786432 bytes, got 0 bytes instead.
   at: create (core/io/image.cpp:1999)
ERROR: Expected Image data size of 320x200x1 (with 8 mipmaps) = 85318 bytes, got 0 bytes instead.
   at: create (core/io/image.cpp:1999)
ERROR: Expected Image data size of 2x2x4 (with 1 mipmap) = 20 bytes, got 0 bytes instead.
   at: create (core/io/image.cpp:1999)
ERROR: The Image width specified (0 pixels) must be greater than 0 pixels.
   at: create (core/io/image.cpp:1947)
ERROR: The Image format specified (9999) is out of range. See Image's Format enum.
   at: create (core/io/image.cpp:1955)

@Calinou Calinou requested a review from a team as a code owner April 10, 2022 23:12
@Calinou Calinou added enhancement topic:core cherrypick:3.x Considered for cherry-picking into a future 3.x release labels Apr 10, 2022
@Calinou Calinou added this to the 4.0 milestone Apr 10, 2022
The rationale behind the expected number of bytes is now displayed
in clear (width, height, format, number of mipmaps expected if any).
@Calinou Calinou force-pushed the image-improve-error-messages branch from 09cdc22 to 18e9e6a Compare April 10, 2022 23:13
@akien-mga akien-mga merged commit d6edc6d into godotengine:master May 16, 2022
@akien-mga
Copy link
Member

Thanks!

@akien-mga
Copy link
Member

Cherry-picked for 3.5.

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label May 16, 2022
@Calinou Calinou deleted the image-improve-error-messages branch May 16, 2022 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants