-
-
Notifications
You must be signed in to change notification settings - Fork 589
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
Crash when passing an object with type hint as parameter to a GDExtension function #1020
Comments
Confirming this happens on macOS as well. macOS 12.6.3 Stack trace
I worked on debugging it and got as far as looking into the VM. In this case: var example:Example = Example.new()
var ref= ExampleRef.new()
example.extended_ref_checks(ref) the extension is being called with // gdscript_vm.cpp around line 1683
method->call(base_obj, (const Variant **)argptrs, argc, err); In this case, however: var example:Example = Example.new()
var ref: ExampleRef = ExampleRef.new()
example.extended_ref_checks(ref) the extension is being called with // gdscript_vm.cpp around line 1971
method->ptrcall(base_obj, argptrs, ret_opaque); So it seems that the VM is choosing the wrong code path when types are present on both vars. I'm not sure who the VM person is to ping, but hopefully the problem will be clear to them. |
It does feel like the issue is on the godot side since it's calling through two different code paths.
I wonder if @vnen is the right person to give input? (Apologies for the ping if not!) |
I believe this is a similar issue to the one that was fixed by @RandomShaper in #72654 I guess the fix did not spill over to GDExtension because they are set externally. So to be consistent it probably should be added to the API a way to set whether the return value is a raw object or not (this would be handled by godot-cpp so it would be transparent for the users).
This is not a bug BTW, it is an optimization. When the types are exact GDScript can do a ptrcall directly, which is faster than a regular call (since the latter will use dynamic dispatch). When it can't tell the types in advance it has to fallback to the dynamic dispatch. |
I'm not sure if I'm understanding if this is about an object being returned of being passed as an argument. |
Version: Godot Engine v4.0.beta16.official.518b9e580
MSVC 19.33.31630 for x64
When passing an instance of an Object with type hint as a parameter to a GDExtension function the running game will crash. This issue is only present when using the type hint for the object variable and for the instance the function is being called on. If the type hint is not provided in one of the two cases, it will not cause a crash. The crash can be reproduced by following this minimal example:
Note: If the type hint for the object variable or the initial example class insstance is not provided, the engine does not crash:
Stack trace:
In the example project of this repo you can do this to trigger the crash:
The text was updated successfully, but these errors were encountered: