To reproduce:
Create a recursive usercommand:
/** recSum */ double n = param(1); return (n > 1) ? n + recSum(n - 1) : n;
Call recSum(aBigNumber). recSum(400) is enough to crash FlexSim on my machine.
The problems with the current behavior are:
- Data and unsaved changes are lost.
- Errors in user code can crash the entire process.
- Occasionally, FlexSim configuration gets corrupted, and the all subsequent attempts to run FlexSim lead to a crash on start (known workaround: reinstall FlexSim).
Proposal:
- throw an exception to inform the user
- unwind the call stack
A similar `recSum(999)` in Python leads to just
RecursionError: maximum recursion depth exceeded in comparison
A similar `recSum(18000)` in Javascript/nodejs is also safe:
RangeError: Maximum call stack size exceeded