Skip to content

Commit e7ebb0f

Browse files
Masadowfacontidavide
authored andcommitted
Fixed a crash occuring when you didn't initialized a Tree object (#20)
1 parent af22b2a commit e7ebb0f

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

include/behaviortree_cpp/xml_parsing.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,23 @@ struct Tree
3737
{
3838
TreeNode* root_node;
3939
std::vector<TreeNode::Ptr> nodes;
40+
41+
Tree() : root_node(nullptr)
42+
{
43+
44+
}
45+
46+
Tree(TreeNode* root_node, std::vector<TreeNode::Ptr> nodes)
47+
: root_node(root_node), nodes(nodes)
48+
{
49+
50+
}
51+
4052
~Tree()
4153
{
42-
haltAllActions(root_node);
54+
if (root_node) {
55+
haltAllActions(root_node);
56+
}
4357
}
4458
};
4559

src/xml_parsing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ Tree buildTreeFromText(const BehaviorTreeFactory& factory, const std::string& te
543543
std::vector<TreeNode::Ptr> nodes;
544544
auto root = parser.instantiateTree(nodes);
545545
assignBlackboardToEntireTree(root.get(), blackboard);
546-
return {root.get(), nodes};
546+
return Tree(root.get(), nodes);
547547
}
548548

549549
Tree buildTreeFromFile(const BehaviorTreeFactory& factory, const std::string& filename,
@@ -555,6 +555,6 @@ Tree buildTreeFromFile(const BehaviorTreeFactory& factory, const std::string& fi
555555
std::vector<TreeNode::Ptr> nodes;
556556
auto root = parser.instantiateTree(nodes);
557557
assignBlackboardToEntireTree(root.get(), blackboard);
558-
return {root.get(), nodes};
558+
return Tree(root.get(), nodes);
559559
}
560560
}

0 commit comments

Comments
 (0)