Skip to content

Commit 7999e6a

Browse files
committed
Add compatibility version check on startup
1 parent a0a4c0c commit 7999e6a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

gdnative-core/src/init/macros.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ macro_rules! godot_nativescript_init {
3535
return;
3636
}
3737

38+
// Compatibility warning if using in-house Godot version (not applicable for custom ones)
39+
#[cfg(not(feature = "custom-godot"))]
40+
{
41+
let engine = gdnative::api::Engine::godot_singleton();
42+
let info = engine.get_version_info();
43+
44+
if info.get("major").expect("major version") != Variant::new(3)
45+
|| info.get("minor").expect("minor version") != Variant::new(4) {
46+
let string = info.get("string").expect("version str").to::<String>().expect("version str type");
47+
gdnative::log::godot_warn!(
48+
"This godot-rust version is only compatible with Godot 3.4.x; detected version {}.\n\
49+
GDNative mismatches may lead to subtle bugs, undefined behavior or crashes at runtime.\n\
50+
Apply the 'custom-godot' feature if you want to use current godot-rust with another Godot engine version.",
51+
string
52+
);
53+
}
54+
}
55+
3856
let __result = ::std::panic::catch_unwind(|| {
3957
$callback($crate::init::InitHandle::new(handle));
4058
});

0 commit comments

Comments
 (0)