You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Object::~Object() removes all the children and deletes them before the destructor of the derived class. Shouldn't I delete the children myself?
Steps to reproduce
With the code below, destruction of B may lead to a crash. (In my circumstance, the editor crashes when I open the project the second time)
usingnamespacegodot;classA: publicNode {
GDCLASS(A, Node);
protected:staticvoid_bind_methods() {}
public:A() {}
};
classB: publicNode {
GDCLASS(B, Node);
protected:staticvoid_bind_methods() {}
private:
A *a;
public:B(): a(memnew(A)) { this->add_child(this->a); }
~B() {
// a is removed and deleted before destruction, either of the below may lead to a crash// this->remove_child(this->a);memdelete(this->a);
}
};
def_ready():
B.new()
Minimal reproduction project
N/A
The text was updated successfully, but these errors were encountered:
I just realized that the Object part is destructed before the part of the derived class, which make it nonsense to remove the children in the destructor of the derived class. But it is still confusing that the parent help delete/free all the children.
Godot version
4.2
godot-cpp version
4.2
System information
Windows 11
Issue description
Object::~Object() removes all the children and deletes them before the destructor of the derived class. Shouldn't I delete the children myself?
Steps to reproduce
With the code below, destruction of B may lead to a crash. (In my circumstance, the editor crashes when I open the project the second time)
Minimal reproduction project
N/A
The text was updated successfully, but these errors were encountered: