godotengine / godotengine/godot-cpp

Godot crashes when using `cast_to` on a node that precedes GDNative node in tree

Open
#860 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.7k
Forks
809
Avg merge
1d 3h
Merged PRs (30d)
8

Description

First of all, sorry for no stack trace: this is reproducible only with `release` builds for some reason...

Here's my code:
```cpp
// goapplanner.cpp
void GOAPPlanner::initialize(Array actions) {
Godot::print(Object::cast_to(actions[0])->get("name").operator String());
}
```

Here's the tree:
```
- parent
- agent
- empty_node (empty node of type Node with nothing inside)
- goapplanner (with GDNS running previous code)
```

Within `agent`, I have the following code:
```gdscript
func _ready():
$goapplanner.initialize([$empty_node])
```
The above code succeeds and prints `empty_node`. However, when I unload the scene to load another (by using `parent.queue_free()`), the game segfaults.

If I move `empty_node` AFTER `goapplanner`, the crash does not happen.

This is strange since I don't even keep the reference to `Node*` anywhere, I just cast `actions[0]` to `Node*` and then throw it away. Do `cast_to`-ed objects have to be marked/freed somehow?

Any ideas about what's going on here?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.