Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GDExtension] Cannot convert Variant to other types correctly #75757

Closed
Pylgos opened this issue Apr 6, 2023 · 0 comments · Fixed by #75758
Closed

[GDExtension] Cannot convert Variant to other types correctly #75757

Pylgos opened this issue Apr 6, 2023 · 0 comments · Fixed by #75758

Comments

@Pylgos
Copy link
Contributor

Pylgos commented Apr 6, 2023

Godot version

4.0.2.stable.official.7a0977ce2

System information

Linux

Issue description

The following code fails with godot-cpp

Variant variant_int = 1234;
double double_value = variant_int;
UtilityFunctions::print(double_value); // prints 0. it must be 1234

Variant double_variant = 6789.0;
int int_value = double_variant;
UtilityFunctions::print(int_value); // prints 0. it must be 1234

Variant variant_string = "12345";
StringName string_name = variant_string;
UtilityFunctions::print(string_name); // Segmentation Fault!

When godot-cpp converts a Variant to another type, it calls type_from_variant_constructor without checking its type. It only does reinterpret_cast and does no type conversion.
I think this issue can be solved by implementing type conversion on the godot-cpp side or by making type_from_variant_constructor do the type conversion.

Steps to reproduce

Unzip the minimal reproduction project and run scons to build the GDExtension.

Minimal reproduction project

variant-conversion-issue.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants