Skip to content

Commit 040fdf0

Browse files
bors[bot]chitoyuu
andauthored
Merge #1002
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>
2 parents 8ac4fae + 1cde99e commit 040fdf0

File tree

11 files changed

+53
-28
lines changed

11 files changed

+53
-28
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.11.2] - 2023-01-09
9+
10+
This is a hot-fix release for a high priority issue.
11+
12+
### Fixed
13+
14+
- API methods that may return null object pointers should no longer panic. ([#1002](https://github.com/godot-rust/gdnative/pull/1002))
15+
816
## [0.11.1] - 2023-01-06
917

1018
This is a backwards-compatible release; thus no removals or breaking changes.

bindings-generator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ documentation = "https://docs.rs/crate/gdnative_bindings_generator"
66
repository = "https://github.com/godot-rust/godot-rust"
77
homepage = "https://godot-rust.github.io/"
88
license = "MIT"
9-
version = "0.11.1"
9+
version = "0.11.2"
1010
workspace = ".."
1111
edition = "2021"
1212
rust-version = "1.63"

gdnative-async/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "Runtime async support for godot-rust."
55
documentation = "https://docs.rs/crate/gdnative-async"
66
repository = "https://github.com/godot-rust/godot-rust"
77
homepage = "https://godot-rust.github.io/"
8-
version = "0.11.1"
8+
version = "0.11.2"
99
license = "MIT"
1010
workspace = ".."
1111
edition = "2021"
@@ -14,9 +14,9 @@ rust-version = "1.63"
1414
[features]
1515

1616
[dependencies]
17-
gdnative-derive = { path = "../gdnative-derive", version = "=0.11.1" }
18-
gdnative-core = { path = "../gdnative-core", version = "=0.11.1" }
19-
gdnative-bindings = { path = "../gdnative-bindings", version = "=0.11.1" }
17+
gdnative-derive = { path = "../gdnative-derive", version = "=0.11.2" }
18+
gdnative-core = { path = "../gdnative-core", version = "=0.11.2" }
19+
gdnative-bindings = { path = "../gdnative-bindings", version = "=0.11.2" }
2020
atomic-waker = "1"
2121
crossbeam-channel = "0.5"
2222
futures-task = "0.3"

gdnative-bindings/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "The Godot game engine's automatcally generated bindings to Godot
55
documentation = "https://docs.rs/crate/gdnative-bindings"
66
repository = "https://github.com/godot-rust/godot-rust"
77
homepage = "https://godot-rust.github.io/"
8-
version = "0.11.1"
8+
version = "0.11.2"
99
license = "MIT"
1010
workspace = ".."
1111
edition = "2021"
@@ -18,8 +18,8 @@ custom-godot = ["gdnative_bindings_generator/custom-godot"]
1818
ptrcall = ["gdnative_bindings_generator/ptrcall"]
1919

2020
[dependencies]
21-
gdnative-core = { path = "../gdnative-core", version = "=0.11.1" }
21+
gdnative-core = { path = "../gdnative-core", version = "=0.11.2" }
2222
libc = "0.2"
2323

2424
[build-dependencies]
25-
gdnative_bindings_generator = { path = "../bindings-generator", version = "=0.11.1" }
25+
gdnative_bindings_generator = { path = "../bindings-generator", version = "=0.11.2" }

gdnative-core/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "The Godot game engine's gdnative core bindings."
55
documentation = "https://docs.rs/crate/gdnative-core"
66
repository = "https://github.com/godot-rust/godot-rust"
77
homepage = "https://godot-rust.github.io/"
8-
version = "0.11.1"
8+
version = "0.11.2"
99
license = "MIT"
1010
workspace = ".."
1111
edition = "2021"
@@ -17,9 +17,9 @@ gd-test = []
1717
type-tag-fallback = []
1818

1919
[dependencies]
20-
gdnative-sys = { path = "../gdnative-sys", version = "=0.11.1" }
21-
gdnative-derive = { path = "../gdnative-derive", version = "=0.11.1" }
22-
gdnative-impl-proc-macros = { path = "../impl/proc-macros", version = "=0.11.1" }
20+
gdnative-sys = { path = "../gdnative-sys", version = "=0.11.2" }
21+
gdnative-derive = { path = "../gdnative-derive", version = "=0.11.2" }
22+
gdnative-impl-proc-macros = { path = "../impl/proc-macros", version = "=0.11.2" }
2323
ahash = "0.8"
2424
approx = "0.5"
2525
atomic-take = "1"

gdnative-core/src/core_types/variant.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,14 @@ impl Variant {
451451
/// Returns true if this is an empty variant.
452452
#[inline]
453453
pub fn is_nil(&self) -> bool {
454-
self.get_type() == VariantType::Nil
454+
match self.get_type() {
455+
VariantType::Nil => true,
456+
VariantType::Object => {
457+
let ptr = unsafe { (get_api().godot_variant_as_object)(&self.0) };
458+
ptr.is_null()
459+
}
460+
_ => false,
461+
}
455462
}
456463

457464
#[inline]

gdnative-derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "The Godot game engine's gdnative derive and procedural macros."
55
documentation = "https://docs.rs/crate/gdnative-derive"
66
repository = "https://github.com/godot-rust/godot-rust"
77
homepage = "https://godot-rust.github.io/"
8-
version = "0.11.1"
8+
version = "0.11.2"
99
license = "MIT"
1010
workspace = ".."
1111
edition = "2021"

gdnative-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "Generated bindings to the Godot game engine's gdnative core types
55
documentation = "https://docs.rs/crate/gdnative-sys"
66
repository = "https://github.com/godot-rust/godot-rust"
77
homepage = "https://godot-rust.github.io/"
8-
version = "0.11.1"
8+
version = "0.11.2"
99
build = "build.rs"
1010
license = "MIT"
1111
workspace = ".."

gdnative/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ keywords = ["gamedev", "godot", "engine", "bindings"]
66
documentation = "https://docs.rs/crate/gdnative"
77
repository = "https://github.com/godot-rust/godot-rust"
88
homepage = "https://godot-rust.github.io/"
9-
version = "0.11.1"
9+
version = "0.11.2"
1010
license = "MIT"
1111
workspace = ".."
1212
readme = "../README.md"
@@ -28,10 +28,10 @@ gd-test = ["gdnative-core/gd-test"]
2828
type-tag-fallback = ["gdnative-core/type-tag-fallback"]
2929

3030
[dependencies]
31-
gdnative-derive = { path = "../gdnative-derive", version = "=0.11.1" }
32-
gdnative-core = { path = "../gdnative-core", version = "=0.11.1" }
33-
gdnative-bindings = { path = "../gdnative-bindings", version = "=0.11.1" }
34-
gdnative-async = { path = "../gdnative-async", version = "=0.11.1", optional = true }
31+
gdnative-derive = { path = "../gdnative-derive", version = "=0.11.2" }
32+
gdnative-core = { path = "../gdnative-core", version = "=0.11.2" }
33+
gdnative-bindings = { path = "../gdnative-bindings", version = "=0.11.2" }
34+
gdnative-async = { path = "../gdnative-async", version = "=0.11.2", optional = true }
3535

3636
[dev-dependencies]
3737
trybuild = "1.0.18" # earrlier versions use broken termcolor 1.0.0

impl/proc-macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ authors = ["The godot-rust developers"]
44
description = "Internal dependency of the gdnative bindings."
55
repository = "https://github.com/godot-rust/godot-rust"
66
homepage = "https://godot-rust.github.io/"
7-
version = "0.11.1"
7+
version = "0.11.2"
88
license = "MIT"
99
workspace = "../.."
1010
edition = "2021"

0 commit comments

Comments
 (0)