-
-
Notifications
You must be signed in to change notification settings - Fork 249
Provide error context for typed array clone check #1348
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
base: master
Are you sure you want to change the base?
Conversation
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-1348 |
This patch adds output of `ConvertError`'s `Display` to debug-only check's panic message which provides additional context when type mismatch happens. Panic message would include the intended type name and what was given instead of it. The output would look roughly like this: ``` copied array should have same type as original array: expected array of type Builtin(DICTIONARY), got Untyped: [] ```
c85aa9c
to
e420f5f
Compare
In which scenario did you encounter this |
@TitanNano I've started getting this exception in debug builds after upgrade from gdext 0.3.5 to 0.4.0, with both Godot 4.4 and 4.5. I've noticed there's another panic which provides the similar context and message, so this patch is probably not needed:
For context: I have a node with #[export]
pub equipment: Array<Dictionary>, In signal handler, I do I'd like to try and reproduce it on a smaller project to check if if happens consistently, or to bisect the changes which happened between 0.3.5 and 0.4. |
Please, do, if you will be able to replicate it then we should be able to provide a fix (or at least an explanation 😅) |
I've bisected and found out that the issue began to appear after #1304. I'll try to reproduce it with a smaller project to understand better why type check might fail. |
I think I've managed to reproduce the issue in the controlled environment. The problem appears to be happening right after let mut equipment = Array::<Dictionary>::new();
godot_warn!("Type before duplicate: {:?}", equipment.element_type()); // shows the correct type
equipment = equipment.duplicate_shallow(); // or duplicate_deep()
godot_warn!("Type after duplicate: {:?}", equipment.element_type()); // <- panics |
So, it appears that As a workaround, resetting // godot-core/src/builtin/collections/array.rs:553
let mut duplicate: VariantArray = unsafe { self.as_inner().duplicate(true) };
duplicate.cached_element_type = OnceCell::new(); ...so subsequent call to UPD: Ah, so there's |
I think the right thing to do would be changing the return type of i.e. going from pub unsafe fn duplicate(&self, deep: bool,) -> VariantArray {
type CallRet = VariantArray;
type CallParams = (bool,);
let args = (deep,);
unsafe {
let method_bind = sys::builtin_method_table() . fptr_by_index(...);
Signature::< CallParams, CallRet > ::out_builtin_ptrcall(method_bind, "Array", "duplicate", self.sys_ptr, args)
}
} to pub unsafe fn duplicate<T>(&self, deep: bool,) -> Array<T> {
type CallRet = Array<T>;
type CallParams = (bool,);
let args = (deep,);
unsafe {
let method_bind = sys::builtin_method_table() . fptr_by_index(...);
Signature::< CallParams, CallRet > ::out_builtin_ptrcall(method_bind, "Array", "duplicate", self.sys_ptr, args)
}
} |
{
"name": "duplicate",
"return_type": "Array",
"is_vararg": false,
"is_const": true,
"is_static": false,
"hash": 636440122,
"arguments": [
{
"name": "deep",
"type": "bool",
"default_value": "false"
}
]
}, ...unless there's a way to have a special handling for this codegen. Otherwise, it seems like either initial type cache value should be non-initialized for all |
this is fully on our side, so we would have to make special exception I'll look into it tomorrow/on Tuesday |
GDExtension doesn't support generic signatures, so cases like these cannot be detected by the code generator. In the past, using Your idea is a bit cleaner but may add more complex special casing 🤔 I think both are valid approaches. In Godot itself this isn't a problem, because GDScript doesn't care about getting variance correct, so you can always convert Are other methods affected by this as well? Immediately coming to mind are |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR itself looks good, but we should additionally fix the real issue 🙂 thanks!
This patch adds output of
ConvertError
'sDisplay
to debug-only check's panic message which provides additional context when type mismatch happens.Panic message would include the intended type name and what was given instead of it.
The output would look roughly like this: