Don't crash on printing nested types

When adding an Array or Dictionary to itself operator String() got in an
infinite loop. This commit adds a stack to operator String() (Through
the use of a new 'stringify method'). This stack keeps track of all
unique Arrays and Dictionaries it has seen. When a duplicate is found
only a static string is printed '[...]' or '{...}'.

This mirror Python's behavior in a similar case.
This commit is contained in:
Hein-Pieter van Braam-Stewart
2019-04-20 01:57:29 +02:00
parent 8e652a1400
commit 8b1e297fc6
8 changed files with 44 additions and 4 deletions

View File

@ -401,6 +401,7 @@ public:
bool hash_compare(const Variant &p_variant) const;
bool booleanize() const;
String stringify(List<const void *> &stack) const;
void static_assign(const Variant &p_variant);
static void get_constructor_list(Variant::Type p_type, List<MethodInfo> *p_list);