You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
null is returned and an error is logged. Attempts to access methods on the return value will result in an “Attempt to call on a null instance.”.
so I expected that null would map to None in rust. Instead get_node panics with the message Unexpected variant type: InvalidNil. This was discussed on Discord and recommended to be reported here.
A short example that reproducers this panic:
use gdnative::prelude::*;#[derive(NativeClass)]#[inherit(Node)]structExampleGetNodeThatDoesNotExistPanics{}implExampleGetNodeThatDoesNotExistPanics{fnnew(_base:&Node) -> Self{Self{}}}#[methods]implExampleGetNodeThatDoesNotExistPanics{#[method]fn_ready(&mutself,#[base]_base:&Node){godot_print!("ExampleGetNodeThatDoesNotExistPanics _ready about to get_node");let _ = _base.get_node("does not exist");// panics with message: "Unexpected variant type: InvalidNil"godot_print!("ExampleGetNodeThatDoesNotExistPanics this line never executes due to panic");}}fninit(handle:InitHandle){
handle.add_class::<ExampleGetNodeThatDoesNotExistPanics>();}godot_init!(init);
and the error message and backtrace:
ERROR: (Node not found: "does not exist" (relative to "/root/Scene").)
at: get_node (scene/main/node.cpp:1465)
thread '<unnamed>' panicked at 'Unexpected variant type: InvalidNil', /home/dave/home/gdnative-get-node-panic-example/target/debug/build/gdnative-bindings-cfa8e4943b33c4de/out/generated.rs:1977:23307
stack backtrace:
0: rust_begin_unwind
at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/std/src/panicking.rs:575:5
1: core::panicking::panic_fmt
at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/core/src/panicking.rs:65:14
2: core::result::unwrap_failed
at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/core/src/result.rs:1791:5
3: core::result::Result<T,E>::expect
at /rustc/69f9c33d71c871fc16ac445211281c6e7a340943/library/core/src/result.rs:1070:23
4: gdnative_bindings::generated::node::<impl gdnative_bindings::generated::node::private::Node>::get_node
at /home/dave/home/gdnative-get-node-panic-example/target/debug/build/gdnative-bindings-cfa8e4943b33c4de/out/generated.rs:1977:23209
5: gdnative_get_node_panic_example::ExampleGetNodeThatDoesNotExistPanics::_ready
1002: Catch null object pointers in Variant::is_nil r=chitoyuu a=chitoyuu
With varcall, Godot sometimes return null objects as Variants with `VariantType::Object` but a null pointer, instead of the usually expected/assumed `VariantType::Nil`. This caused `Option::from_variant` to panic in case of null objects returned by Godot in this way.
Fix#1001
Co-authored-by: Chitose Yuuzaki <chitoyuu@potatoes.gay>
When I use Node::get_node to retrieve a Node that does not exist, according to the documentation
so I expected that
null
would map toNone
in rust. Insteadget_node
panics with the messageUnexpected variant type: InvalidNil
. This was discussed on Discord and recommended to be reported here.A short example that reproducers this panic:
and the error message and backtrace:
A small Godot project reproducing the problem: gdnative-get-node-panic-example.zip
The text was updated successfully, but these errors were encountered: