+1 vote

I just started trying to rewrite some of my code in C++ to make it more performant, but I'm running into some trouble using Godot's internal types within c++ due to the lack of documentation. I followed the GDNative C++ example on on Github and I'm trying to write a function the will take in a texture and convert it to an array of floats. But right now I'm just trying to figure out how to even call Texture.get_data().

My project structure is the same as the example, but my class is called Cubifier rather than GDTest

here is my cubifier.cpp:

#include "cubifier.hpp"


using namespace godot;

void Cubifier::_register_methods() {
    register_method("set_heightmap", &Cubifier::set_heightmap);
    register_method("get_heightmap", &Cubifier::get_heightmap);
}

void Cubifier::_init() {
}

void Cubifier::set_heightmap(Ref<Texture> new_heightmap) {
    _heightmap = new_heightmap->get_data();
}

Ref<Image> Cubifier::get_heightmap() const{
    return _heightmap;
}

and my cubifier.hpp:

#ifndef Cubifier_HPP
#define Cubifier_HPP

#include <Godot.hpp>
#include <Node2D.hpp>
#include <Image.hpp>
#include <Texture.hpp>

namespace godot {

class Cubifier : public Node2D {
    GODOT_CLASS(Cubifier, Node2D)

private:
    Ref<Image> _heightmap;

public:
    static void _register_methods();

    void _init();

    void set_heightmap(Ref<Texture> new_heightmap);
    Ref<Image> get_heightmap() const;
};

}

#endif /* !Cubifier_HPP */

When I run SCons, everything builds fine but when I try to run my project in Godot, I immediately get:

 drivers/unix/net_socket_posix.cpp:190 - Socket error: 10054

Here is where I call the functions in godot

var test = load("res://bin/cubifier.gdns").new()
test.set_heightmap(height_map_img)
test.get_heightmap()

where height_map_img is just an image that works perfectly fine everywhere else

asked Jan 24 in Engine by TheLoveDoctor (22 points)
edited Jan 25 by TheLoveDoctor

In your gdscript, are you passing an image to test.set_heightmap when it is expecting a texture?

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.