Working with TypedArray in C++

TypedArray<B>

1 Like

when I add value to it in the editor and run it on Android, gives me an error:

at: load (core/io/resource_format_binary.cpp:762)
08-02 10:52:17.716 10664 10826 E godot   : USER ERROR: Failed loading resource: res://.godot/exported/133200997/export-f47528efc383e396a0647f9294453713-a.scn. Make sure resources have been imported by opening the project in the editor at least once.
08-02 10:52:17.716 10664 10826 E godot   :    at: _load (core/io/resource_loader.cpp:275)
08-02 10:52:17.716 10664 10826 E godot   : USER ERROR: Failed loading scene: res://a.tscn.
08-02 10:52:17.716 10664 10826 E godot   :    at: start (main/main.cpp:3475)

Yeah, I’m not pretty sure what’s the cause about this kind of Make sure resources have been imported by opening the project in the editor at least once errors. I didn’t encounter this error recently, usually I reboot the editor. However you met this on your android build, this is always weird and unpredictable to me.

Could it be the problem with the set and get methods?

    void set_bs(const TypedArray<B> bs);
    TypedArray<B> get_bs() const;
void A::set_bs(const TypedArray<B> bs) {
	this->bs = bs;
}

TypedArray<B> A::get_bs() const {
	return bs;
}

Can you remember what internal types is using arrays that being bound? I think we could take a look at what did those code have done.

U mean my type of B? is resource

I mean do you remember some types of Godot that has arrays exported in the inspector? We can take them as examples of how should we do that.

I don’t know, maybe MultiMesh?

Brilliant! I’ve noticed this declaration.

void set_buffer(const Vector<float> &p_buffer);
Vector<float> get_buffer() const;

This did proves my thought of we should use references. The reason of the get_buffer returns by value is it’s storing a Vector<float>. In your case, the element type is a Resource, so my idea is returning the array by reference on setter and getter both.

so, what to do now?

void set_bs(const TypedArray<B>& bs);
TypedArray<B>& get_bs() const;
TypedArray<B>& A::get_bs() const {
	return bs;
}

Error:
qualifiers dropped in binding reference of type "godot::TypedArray<godot::B> &" to initializer of type "const godot::TypedArray<godot::B>"C/C++(433)

skeleton2d

This might mean that the getter of arrays must returning by value.

should I report it in GitHub?

This is more like a lacking of tutorials about writing C++ interface in Godot. You can check out the GDExtension series of Mohsen Zare on Youtube.