GDScript: Add limit to call depth

The hard limit is set at 2048 depth which seems sensible between
legitimate recursive calls while still avoiding a crash because of a
stack overflow in most of the cases.

Note that it is still possible to reach the stack limit and get an
overflow before reaching a call depth. This is intended as a half-way
measure to stop crashing in most cases, since there's no reliable nor
portable way to check the amount of stack memory left.
This commit is contained in:
George Marques 2023-02-07 17:09:40 -03:00
parent a05670c617
commit 34f0a2ca46
No known key found for this signature in database
GPG key ID: 046BD46A3201E43D
3 changed files with 35 additions and 1 deletions

View file

@ -544,6 +544,8 @@ private:
#endif
public:
static constexpr int MAX_CALL_DEPTH = 2048; // Limit to try to avoid crash because of a stack overflow.
struct CallState {
GDScript *script = nullptr;
GDScriptInstance *instance = nullptr;