Blit_rect throws error Condition "dsize == 0" is true

Godot Version



Found some instructions regarding blit here and tried it out:

My code is

func _ready():
	var img =
	img.create(1200, 1200, false, Image.FORMAT_RGB8)
	var blitImage =
	img.blit_rect(blitImage, blitImage.get_used_rect(), Vector2(40, 40))

but when I run it, it returns

E 0:00:00:0578 @ _ready(): Condition "dsize == 0" is true.
  <C++ Source>   core/io/image.cpp:2786 @ blit_rect()
  <Stack Trace> @ _ready()

E 0:00:00:0578 @ _ready(): Condition "p_img.is_null() || p_img->is_empty()" is true. Returning: ERR_INVALID_PARAMETER
  <C++ Source>   modules/jpg/image_loader_jpegd.cpp:158 @ _jpgd_save_to_output_stream()
  <Stack Trace> @ _ready()

I have already checked, according to the Godot inspector the avatar.jpg is of format RGB8 so that can be ruled out as issue.
What am I missing here?

You can find the complete project here for reference:

1 Like

Hi, you need to save the return value of Image.create().

	img = img.create(1200, 1200, false, Image.FORMAT_RGB8)

@shatteredreality thanks, I missed that in the documentation. :person_facepalming:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.