gdext icon indicating copy to clipboard operation
gdext copied to clipboard

_Virtual trait functions unable to handle panic

Open dot-underscore-dot opened this issue 1 year ago • 2 comments

I have discovered that when a panic occurs in the _Virtual trait functions; such as init, ready, draw, and process; the game (or editor in the case of init) would hang for a few seconds then silently close. When the game crashes, the errors do not appear in the error tab as expected. When observing the terminal during the init and ready crashes, the following backtraces are generated

Initialize GDExtension API for Rust: Godot Engine v4.1.1.stable.arch_linux
Godot Engine v4.1.1.stable.arch_linux - https://godotengine.org
Vulkan API 1.3.246 - Forward Mobile - Using Vulkan Device #0: Intel - Intel(R) Graphics (ADL GT2)
 
thread '<unnamed>' panicked at 'init', src/error_test.rs:23:9
stack backtrace:
   0:     0x7f96a4f9d15a - std::backtrace_rs::backtrace::libunwind::trace::h9a6b80bbf328ba5d
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f96a4f9d15a - std::backtrace_rs::backtrace::trace_unsynchronized::hd162ec543a11886b
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f96a4f9d15a - std::sys_common::backtrace::_print_fmt::h78a5099be12f51a6
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f96a4f9d15a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::ha1c5390454d74f71
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f96a4fbb15f - core::fmt::write::h9ffde816c577717b
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/fmt/mod.rs:1254:17
   5:     0x7f96a4f9add5 - std::io::Write::write_fmt::h88186074961638e4
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/io/mod.rs:1698:15
   6:     0x7f96a4f9cf25 - std::sys_common::backtrace::_print::h184198273ed08d59
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7f96a4f9cf25 - std::sys_common::backtrace::print::h1b4d8e7add699453
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7f96a4f9e61e - std::panicking::default_hook::{{closure}}::h393bcea75423915a
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:269:22
   9:     0x7f96a4f9e3c5 - std::panicking::default_hook::h48c64f31d8b3fd03
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:288:9
  10:     0x7f96a4f9ed04 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hb9b860f5a1175bda
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/alloc/src/boxed.rs:1987:9
  11:     0x7f96a4f9ed04 - std::panicking::rust_panic_with_hook::hafdc493a79370062
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:695:13
  12:     0x7f96a4f9ea32 - std::panicking::begin_panic_handler::{{closure}}::h0a64bc82e36bedc7
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:580:13
  13:     0x7f96a4f9d5c6 - std::sys_common::backtrace::__rust_end_short_backtrace::hc203444fb7416a16
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:150:18
  14:     0x7f96a4f9e7d2 - rust_begin_unwind
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:578:5
  15:     0x7f96a4e0ddc3 - core::panicking::panic_fmt::h0f6ef0178afce4f2
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:67:14
  16:     0x7f96a4e1fff2 - <error_test::error_test::ErrorTest as godot_core::gen::classes::node_2d::re_export::Node2DVirtual>::init::hbd4e58a5da555462
                               at /home/puwa/Documents/godot/error-test/error_test/src/error_test.rs:23:3
  17:     0x7f96a4e2039d - <error_test::error_test::ErrorTest as godot_core::obj::traits::cap::GodotInit>::__godot_init::ha487a0799e2d7c34
                               at /home/puwa/Documents/godot/error-test/error_test/src/error_test.rs:20:1
  18:     0x7f96a4e213e7 - core::ops::function::FnOnce::call_once::h2ca7cd0ec9a6e389
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/function.rs:250:5
  19:     0x7f96a4e10400 - godot_core::registry::callbacks::create_custom::h05735c1377c382d5
                               at /home/puwa/.cargo/git/checkouts/gdext-76630c89719e160c/0d4670f/godot-core/src/registry.rs:316:29
  20:     0x7f96a4e109da - godot_core::registry::callbacks::create::he575195e9301cb6d
                               at /home/puwa/.cargo/git/checkouts/gdext-76630c89719e160c/0d4670f/godot-core/src/registry.rs:299:9
  21:     0x55e2bbceb8b2 - <unknown>
  22:     0x55e2b8f19d1e - <unknown>
  23:     0x55e2b8f64210 - <unknown>
  24:     0x55e2bbf7108c - <unknown>
  25:     0x55e2b90bc0cc - <unknown>
  26:     0x55e2b82d0bfb - <unknown>
  27:     0x55e2b823288d - <unknown>
  28:     0x7f96b2627cd0 - <unknown>
  29:     0x7f96b2627d8a - __libc_start_main
  30:     0x55e2b82413e5 - <unknown>
  31:                0x0 - <unknown>
fatal runtime error: failed to initiate panic, error 5
Initialize GDExtension API for Rust: Godot Engine v4.1.1.stable.arch_linux
Godot Engine v4.1.1.stable.arch_linux - https://godotengine.org
Vulkan API 1.3.246 - Forward Mobile - Using Vulkan Device #0: Intel - Intel(R) Graphics (ADL GT2)
 
thread '<unnamed>' panicked at 'ready', src/error_test.rs:33:13
stack backtrace:
   0:     0x7f33e2b9d13a - std::backtrace_rs::backtrace::libunwind::trace::h9a6b80bbf328ba5d
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f33e2b9d13a - std::backtrace_rs::backtrace::trace_unsynchronized::hd162ec543a11886b
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f33e2b9d13a - std::sys_common::backtrace::_print_fmt::h78a5099be12f51a6
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f33e2b9d13a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::ha1c5390454d74f71
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f33e2bbb13f - core::fmt::write::h9ffde816c577717b
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/fmt/mod.rs:1254:17
   5:     0x7f33e2b9adb5 - std::io::Write::write_fmt::h88186074961638e4
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/io/mod.rs:1698:15
   6:     0x7f33e2b9cf05 - std::sys_common::backtrace::_print::h184198273ed08d59
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7f33e2b9cf05 - std::sys_common::backtrace::print::h1b4d8e7add699453
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7f33e2b9e5fe - std::panicking::default_hook::{{closure}}::h393bcea75423915a
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:269:22
   9:     0x7f33e2b9e3a5 - std::panicking::default_hook::h48c64f31d8b3fd03
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:288:9
  10:     0x7f33e2b9ece4 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hb9b860f5a1175bda
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/alloc/src/boxed.rs:1987:9
  11:     0x7f33e2b9ece4 - std::panicking::rust_panic_with_hook::hafdc493a79370062
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:695:13
  12:     0x7f33e2b9ea12 - std::panicking::begin_panic_handler::{{closure}}::h0a64bc82e36bedc7
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:580:13
  13:     0x7f33e2b9d5a6 - std::sys_common::backtrace::__rust_end_short_backtrace::hc203444fb7416a16
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:150:18
  14:     0x7f33e2b9e7b2 - rust_begin_unwind
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:578:5
  15:     0x7f33e2a0ddc3 - core::panicking::panic_fmt::h0f6ef0178afce4f2
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:67:14
  16:     0x7f33e2a2003a - <error_test::error_test::ErrorTest as godot_core::gen::classes::node_2d::re_export::Node2DVirtual>::ready::h8fe1ad89c81c02b7
                               at /home/puwa/Documents/godot/error-test/error_test/src/error_test.rs:33:13
  17:     0x7f33e2a12e5c - <error_test::error_test::ErrorTest as godot_core::obj::traits::cap::ImplementsGodotVirtual>::__virtual_call::function::{{closure}}::h27317f4e62209e8d
                               at /home/puwa/Documents/godot/error-test/error_test/src/error_test.rs:20:1
  18:     0x7f33e2a21f78 - core::ops::function::FnOnce::call_once::hfd3384b0f710c6f9
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/function.rs:250:5
  19:     0x7f33e2a151d1 - <(R,) as godot_core::builtin::meta::signature::PtrcallSignatureTuple>::in_ptrcall::h845ed434cefa927d
                               at /home/puwa/.cargo/git/checkouts/gdext-76630c89719e160c/0d4670f/godot-core/src/builtin/meta/signature.rs:274:38
  20:     0x7f33e2a204ad - <error_test::error_test::ErrorTest as godot_core::obj::traits::cap::ImplementsGodotVirtual>::__virtual_call::function::hfa8777e53b945c27
                               at /home/puwa/Documents/godot/error-test/error_test/src/error_test.rs:20:1
  21:     0x557282de7e78 - <unknown>
  22:     0x557284392e38 - <unknown>
  23:     0x5572827e4d66 - <unknown>
  24:     0x5572827e4d04 - <unknown>
  25:     0x5572827e4d04 - <unknown>
  26:     0x557282810263 - <unknown>
  27:     0x557282867973 - <unknown>
  28:     0x5572809738ab - <unknown>
  29:     0x7f33f0227cd0 - <unknown>
  30:     0x7f33f0227d8a - __libc_start_main
  31:     0x5572809823e5 - <unknown>
  32:                0x0 - <unknown>
fatal runtime error: failed to initiate panic, error 5

It is also worth noting that whenever a #[func] function is triggered via a signal or a deferred call (the callee's panic is handled by the call function, however the caller panics due to a "method not found" error), the error is handled with no issues

dot-underscore-dot avatar Sep 23 '23 18:09 dot-underscore-dot

I encountered this as well. I noticed when I ran the scene directly from the command line, the panic error message was printed out. but not inside the godot editor.

I have a branch of my project which will demo this bug when running the rust implementation: https://github.com/dsmiller95/MazePerformanceGrade/blob/panic-example/rust/src/maze_scripts/floor_creator.rs#L37-L41

dsmiller95 avatar Sep 24 '23 16:09 dsmiller95

from what i have checked it appears that godot-core's handle_panic is not applying to these functions, though i am not yet familiar enough with the codebase (mostly regarding the macros) to understand how it's working properly with #[func] functions. the only three instances i have found don't seem to reveal why one should work and the other shouldn't

dot-underscore-dot avatar Sep 24 '23 20:09 dot-underscore-dot