#Can't create properly an Image on Godot 4.0.2 C++ ?

2 messages · Page 1 of 1 (latest)

gusty goblet
#

Hi everyone,
I'm currently trying to create an Image in a GDExtension using C++.
This is the code I've been using for previous releases:

    Ref<godot::Image> image;
    image.instantiate();
    image->create(matrix.width(), matrix.height(), false, godot::Image::FORMAT_RGB8);
    
    UtilityFunctions::print(image->get_width());

Where matrix.width() and matrix.height() are two ints always properly set.
Looks like it is not working anymore. The image->get_width() property shows up to be 0 in console, and in fact if I try to set any pixel on the image I get the following error in the editor

E 0:00:01:0399   Control.gd:17 @ _ready(): Index p_x = 0 is out of bounds (width = 0).
  <C++ Source>   core/io/image.cpp:3278 @ set_pixel()
  <Stack Trace>  Control.gd:17 @ _ready()

Any idea why this might happen?

gusty goblet
#

Solved with this

Ref<godot::Image> image = godot::Image::create(matrix.width(), matrix.height(), false, godot::Image::FORMAT_RGB8);