godotengine / godot-cpp

C++ bindings for the Godot script API
MIT License
1.74k stars 576 forks source link

Passing doubles to methods doesn't seem to work #49

Closed blicksyne closed 5 years ago

blicksyne commented 7 years ago

When trying to call functions that take doubles as arguments (double on the bindings side usually and float internally), the value received by the function in the bindings is correct, but the value received inside the actual function is incorrect. Some examples are: set_rotation_deg, set_rotation, set_rotation_in_degrees. The value received on the engine side is NaN for most functions affected by this. Another affected function is set_anchor. In this case a 0 is received when 1 is passed as the second argument.

My local godot, godot-cpp and godot_headers repositories are up-to-date and I'm on Ubuntu 17.06 using GCC. The issue was also present on Windows 10 using MSVC, before the linking issue on Windows appeared.

karroffel commented 6 years ago

Ah yes, that is because there is no ArgCast for doubles.

I'll add it soon

karroffel commented 6 years ago

The problem is that doubles aren't supported in Variant, so it's not useful to use them whenever you interface with Godot. Not much we can do about it here in the bindings :(

karroffel commented 6 years ago

Oh, turns out that there is a problem here actually. I'll look into this today.

karroffel commented 6 years ago

Actually the problem aren't the doubles, the problem are floats. Godot ptrcall expects all floating point numbers to be passed via double *, even in the case of floats.

This is fixed on the nativescript-1.1 branch, by the commit 2dbc73f.

If there's much demand then this is easy to cherry pick, but I hope to get the nativescript-1.1 branch into a stable state very soon anyway.

BastiaanOlij commented 5 years ago

Seeing nativescript 1.1 has now been merged into master I'm closing this.