Skip to content

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

@and3rson

Description

@and3rson

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

Here's my code:

// goapplanner.cpp
void GOAPPlanner::initialize(Array actions) {
    Godot::print(Object::cast_to<Node>(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:

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions