Skip to content

Commit 631a1fd

Browse files
committed
Added a check for recursive behavior trees while parsing
1 parent d8f3b37 commit 631a1fd

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/xml_parsing.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1111
*/
1212

13+
#include <csignal>
1314
#include <cstdio>
1415
#include <cstring>
1516
#include <functional>
@@ -934,8 +935,17 @@ void BT::XMLParser::PImpl::recursivelyCreateSubtree(const std::string& tree_ID,
934935
}
935936
else // special case: SubTreeNode
936937
{
937-
auto new_bb = Blackboard::create(blackboard);
938938
const std::string subtree_ID = element->Attribute("ID");
939+
940+
// check for recursion in behavior tree
941+
if(prefix.find(subtree_ID) != std::string::npos)
942+
{
943+
auto msg = StrCat("Recursive behavior trees are not supported. A cycle was found in ",
944+
"<Subtree ID=\"", subtree_ID, "\"> with prefix: ", prefix);
945+
throw RuntimeError(msg);
946+
}
947+
948+
auto new_bb = Blackboard::create(blackboard);
939949
std::unordered_map<std::string, std::string> subtree_remapping;
940950
bool do_autoremap = false;
941951

0 commit comments

Comments
 (0)