Skip to content
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

Panic in init function does not catch unwind and crashes editor #919

Open
TrevorCow opened this issue Oct 14, 2024 · 0 comments
Open

Panic in init function does not catch unwind and crashes editor #919

TrevorCow opened this issue Oct 14, 2024 · 0 comments
Labels
bug c: core Core components

Comments

@TrevorCow
Copy link

TrevorCow commented Oct 14, 2024

Running the following project in Godot version Godot Engine v4.3.stable.official.77dcf97d8 will immediately crash the editor on project load, as loading the project calls all the init functions.

lib.rs

use godot::classes::{INode2D, Node2D};
use godot::global::godot_print;
use godot::init::{gdextension, ExtensionLibrary};
use godot::obj::Base;
use godot::register::{godot_api, GodotClass};

struct MyExtension {}

#[gdextension]
unsafe impl ExtensionLibrary for MyExtension {}

#[derive(GodotClass)]
#[class(base=Node2D)]
struct TestObject {
    base: Base<Node2D>,
}

#[godot_api]
impl INode2D for TestObject {
    fn init(_base: Base<Self::Base>) -> Self {
        godot_print!("Hello, world!");
        panic!("Something went wrong with init!")
    }
}

Cargo.toml

[package]
name = "test_godot_rust"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]  # Compile this crate to a dynamic C library.

[dependencies]
godot = { git = "https://github.com/godot-rust/gdext", branch = "master" }

Full console output and stack trace

> Godot_v4.3-stable_win64_console.exe
Godot Engine v4.3.stable.official.77dcf97d8 - https://godotengine.org
OpenGL API 3.3.0 NVIDIA 565.90 - Compatibility - Using Device: NVIDIA - NVIDIA GeForce RTX 3080 Ti

Editing project: C:/Dev/godot/test_project
WARNING: The original path size of 'test_godot_rust.pdb' in bytes was too small to fit the new name, so it was shortened to '~test_godot_rust_999.pdb'.
     at: copy_and_rename_pdb (platform/windows/windows_utils.cpp:182)
Initialize godot-rust (API v4.3.stable.official, runtime v4.3.stable.official)
Godot Engine v4.3.stable.official.77dcf97d8 - https://godotengine.org
OpenGL API 3.3.0 NVIDIA 565.90 - Compatibility - Using Device: NVIDIA - NVIDIA GeForce RTX 3080 Ti

Hello, world!
thread '<unnamed>' panicked at src\lib.rs:22:9:
Something went wrong with init!
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread '<unnamed>' panicked at library\core\src\panicking.rs:221:5:
panic in a function that cannot unwind
stack backtrace:
   0:     0x7ff994c4664d - std::backtrace_rs::backtrace::dbghelp64::trace
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:91
   1:     0x7ff994c4664d - std::backtrace_rs::backtrace::trace_unsynchronized
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2:     0x7ff994c4664d - std::sys::backtrace::_print_fmt
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\sys\backtrace.rs:65
   3:     0x7ff994c4664d - std::sys::backtrace::impl$0::print::impl$0::fmt
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\sys\backtrace.rs:40
   4:     0x7ff994c58719 - core::fmt::rt::Argument::fmt
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\core\src\fmt\rt.rs:173
   5:     0x7ff994c58719 - core::fmt::write
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\core\src\fmt\mod.rs:1182
   6:     0x7ff994c44af1 - std::io::Write::write_fmt<std::sys::pal::windows::stdio::Stderr>
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\io\mod.rs:1827
   7:     0x7ff994c48357 - std::panicking::default_hook::closure$1
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\panicking.rs:269
   8:     0x7ff994c47f49 - std::panicking::default_hook
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\panicking.rs:296
   9:     0x7ff994c48a3b - alloc::boxed::impl$50::call
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\alloc\src\boxed.rs:2084
  10:     0x7ff994c48a3b - std::panicking::rust_panic_with_hook
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\panicking.rs:808
  11:     0x7ff994c4889f - std::panicking::begin_panic_handler::closure$0
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\panicking.rs:667
  12:     0x7ff994c46d3f - std::sys::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\sys\backtrace.rs:168
  13:     0x7ff994c484b6 - std::panicking::begin_panic_handler
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\std\src\panicking.rs:665
  14:     0x7ff994c5ecfd - core::panicking::panic_nounwind_fmt::runtime
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\core\src\panicking.rs:112
  15:     0x7ff994c5ecfd - core::panicking::panic_nounwind_fmt
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\core\src\panicking.rs:122
  16:     0x7ff994c5eda3 - core::panicking::panic_nounwind
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\core\src\panicking.rs:221
  17:     0x7ff994c5ef5b - core::panicking::panic_cannot_unwind
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library\core\src\panicking.rs:309
  18:     0x7ff994a36363 - godot_core::registry::callbacks::create<ship_fight_rust::TestObject>
                               at C:\Users\trevo\.cargo\git\checkouts\gdext-76630c89719e160c\a0d5799\godot-core\src\registry\callbacks.rs:22
  19:     0x7ffa064ef540 - _CxxFrameHandler3
  20:     0x7ffa064e33d8 - is_exception_typeof
  21:     0x7ffa180549c6 - RtlCaptureContext2
  22:     0x7ff994a3633b - godot_core::registry::callbacks::create<test_godot_rust::TestObject>
                               at C:\Users\trevo\.cargo\git\checkouts\gdext-76630c89719e160c\a0d5799\godot-core\src\registry\callbacks.rs:25
  23:     0x7ff7bf6ee44d - <unknown>
  24:     0x7ff7bc058dce - <unknown>
  25:     0x7ff7bc0a86a9 - <unknown>
  26:     0x7ff7bc0d6f99 - <unknown>
  27:     0x7ff7bfc4ffe5 - <unknown>
  28:     0x7ff7bf6da3c1 - <unknown>
  29:     0x7ff7bd3e4740 - <unknown>
  30:     0x7ff7bb028de2 - <unknown>
  31:     0x7ff7bb06557c - <unknown>
  32:     0x7ff7c078c493 - <unknown>
  33:     0x7ff7bafc12ee - <unknown>
  34:     0x7ff7bafc13e6 - <unknown>
  35:     0x7ffa168c257d - BaseThreadInitThunk
  36:     0x7ffa1800af08 - RtlUserThreadStart
thread caused non-unwinding panic. aborting.
@Bromeon Bromeon added bug c: core Core components labels Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug c: core Core components
Projects
None yet
Development

No branches or pull requests

2 participants