Comments (6)
FYI I tried out #136 (looking great!) to see how it handles the _input
function, but it looks like it is running into the same issue: The event: Gd<InputEvent>
provided by the engine seems to be freed already, and trying to do anything with it results in a panic. I'm still unsure if this is a bug in Godot itself, or if there is happening something on the FFI level that causes the object to be invalid.
from gdext.
Just did a small experiment. Interestingly just adding
fn input(&mut self) {
unimplemented!()
}
there and modifying the VIRTUAL_METHOD_NAMES
in godot-macros/src/godot_api.rs
to
const VIRTUAL_METHOD_NAMES: [&str; 4] = ["ready", "input", "process", "physics_process"];
already does seem to do something, i.e., my callback was called successfully.
What didn't work is adding an argument event: InputEvent
, because it doesn't satisfy the GodotFfi
trait. I could imagine that this is the main work to do here, although I haven't figured out yet how the whole function call mechanism works.
from gdext.
What didn't work is adding an argument
event: InputEvent
, because it doesn't satisfy theGodotFfi
trait. I could imagine that this is the main work to do here, although I haven't figured out yet how the whole function call mechanism works.
You could try Gd<InputEvent>
instead of InputEvent
-- all objects need to be transported via Gd
smart pointer.
This fix is relatively easy by itself; just repeat the work for the methods listed -- but that's only half of the story.
We still don't support other virtual functions (declared by classes other than Node
), and need a scalable approach for them. There were mostly two ideas around:
- Generate code for traits in the style of
GodotExt
for other classes.- This might add a ton of highly specialized tiny traits though, and require many
impl
blocks every time.
- This might add a ton of highly specialized tiny traits though, and require many
- Have a "fallback" mechanism to override virtual methods without the type safety.
- Example syntax:
#[func(override)]
in a normalGodotApi
block. Similar to how GDNative works but slightly more explicit.
- Example syntax:
from gdext.
You could try Gd instead of InputEvent
That indeed results in something that compiles, but crashes at runtime (note that it is after the input
method has been called):
[...]
Experiment::input() called
ERROR: Condition "slot >= slot_max" is true. Returning: nullptr
at: get_instance (./core/object/object.h:972)
thread '<unnamed>' panicked at 'as_ref_counted() on freed instance; maybe forgot to increment reference count?', /home/fabian/git/_ext/gdextension/godot-core/src/obj/gd.rs:344:9
stack backtrace:
0: rust_begin_unwind
at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/std/src/panicking.rs:575:5
1: core::panicking::panic_fmt
at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/core/src/panicking.rs:64:14
2: godot_core::obj::gd::Gd<T>::as_ref_counted
at /home/fabian/git/_ext/gdextension/godot-core/src/obj/gd.rs:344:9
3: <godot_core::obj::traits::mem::StaticRefCount as godot_core::obj::traits::mem::Memory>::maybe_dec_ref
at /home/fabian/git/_ext/gdextension/godot-core/src/obj/traits.rs:248:13
4: <godot_core::obj::gd::Gd<T> as core::ops::drop::Drop>::drop
at /home/fabian/git/_ext/gdextension/godot-core/src/obj/gd.rs:539:23
5: core::ptr::drop_in_place<godot_core::obj::gd::Gd<godot_core::gen::classes::input_event::re_export::InputEvent>>
at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/core/src/ptr/mod.rs:490:1
6: <hello_world::experiment::Experiment as godot_core::bind::GodotExt>::input
at ./rust/src/experiment.rs:38:5
7: <hello_world::experiment::Experiment as godot_core::obj::traits::cap::ImplementsGodotExt>::__virtual_call::function
at ./rust/src/experiment.rs:15:1
8: <unknown>
9: <unknown>
10: <unknown>
11: <unknown>
12: <unknown>
13: <unknown>
14: <unknown>
15: <unknown>
16: <unknown>
17: __libc_start_call_main
at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
18: __libc_start_main_impl
at ./csu/../csu/libc-start.c:392:3
19: <unknown>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
fatal runtime error: failed to initiate panic, error 5
This fix is relatively easy by itself; just repeat the work for the methods listed
Still beyond the noob nevel 😉 What actually surprises me that git grep doesn't reveal any other occurrences of e.g. "physics_process", i.e., I haven't really found where the argument passing actually happens.
from gdext.
What actually surprises me that git grep doesn't reveal any other occurrences of e.g. "physics_process", i.e., I haven't really found where the argument passing actually happens.
That's not repeated, but defined here:
https://github.com/godot-rust/gdextension/blob/master/godot-macros/src/godot_api.rs#L262
from gdext.
A few more observations on this. When implementing the input method as
fn input(&mut self, event: Gd<InputEvent>) {
godot_print!("in input");
godot_print!("instance_id: {}", event.instance_id());
godot_print!("is_instance_valid: {}", event.is_instance_valid());
godot_print!("ref count: {}", event.get_reference_count());
godot_print!("event: {}", event);
}
and running with tracing enabled, I'm getting this output:
So interestingly the object we are getting from the engine is already invalid. Whether the ref count makes sense in this case is unclear to me.
The crash comes the attempt to print the event
. Removing that line causes a panic at the end of the generated macro function instead (the __virtual_call
), leading to the backtrace posted above.
I'm wondering if this may require some special handling around gdext_ptrcall!
macro here:
On the other hand, if the object provided by the engine is indeed garbage, we cannot really fix the ref count on Rust side, can we?
from gdext.
Related Issues (20)
- Add option to add_class at init time level HOT 1
- Missing methods from built-in types HOT 2
- GString (and possibly other variant types) are missing methods HOT 2
- Trait bound 'Player: GodotDefault' is not satisfied error during Hello World example HOT 3
- `#[func]` function arguments with invalid types produce weird errors
- Deep copies taking into account Rust state (unlike `Node::duplicate()`) HOT 8
- Array<Option<Gd<_>>> Crashes on Null Pointer in Godot's Editor HOT 2
- Inheritance and polymorphism proposals
- Virtual function dispatch for Resources not working HOT 3
- Add mocks for some builtin types for use when Godot isn't running HOT 5
- Missing classes in `engine` module relating to navigation HOT 1
- Recent commit causes "GDExtension initialization function 'gdext_rust_init' returned an error" HOT 1
- Vector3 signed_angle_to is incorrect
- Simple VideoStreamPlayback causes thread panic HOT 2
- It is possible to have a `Base` pointing to a dead object HOT 1
- Issues with string & sse4 support HOT 3
- Problems related to multithreaded access imposed by Godot
- It is tricky to figure out how to properly use `WithBaseField` generically
- commit() failing for SurfaceTool in simple case HOT 6
- godot endlessly prompting to restart HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gdext.