Image object initialization dose not behave as expected

Godot Version

4.3

Question

Hi everyone,

I’m new to GDExtension in C++, and I’m having trouble creating an Image instance. Here’s what I’m doing:

Ref<Image> slice = memnew(Image);
slice->create_empty(dim_x, dim_y, false, Image::FORMAT_RF);
UtilityFunctions::print(int(slice->get_width())); // Always prints 0

No matter what values I use for dim_x and dim_y, slice->get_width() always returns 0, as if the image isn’t actually being created.

Am I missing something? Do I need to initialize the Image differently in GDExtension? Any help would be greatly appreciated!

Thanks!

Update
Ok, my bad, the function returns the Ref<Image> :sweat_smile:

Ref<Image> slice = Image::create_empty(dim_x, dim_y, false, Image::FORMAT_RF);
UtilityFunctions::print(int(slice->get_width()));

That fixed it!