FiniteStateMachine icon indicating copy to clipboard operation
FiniteStateMachine copied to clipboard

StackOverflow exception

Open kjorgensen opened this issue 3 years ago • 2 comments

I have a state machine that loops around for more than 256,000 times and I eventually get an error The maximum number of stajavascript:void(0);ck frames supported by Visual Studio has been exceeded. Is there a workaround for this. I can see in the call stcack there are now breaks.

kjorgensen avatar Apr 14 '22 21:04 kjorgensen

Uh. Hi there. It's been a few years since I've had a look at this repo, but I think your problem lies with the stack-function of the machine. You're running into a memory-overflow with C#. Let me explain...

Furthermore it implements even a Stack-Based-FSM (SBFSM). So you may tell it to 'continue with the last state before the active one'.

The stack-function means that you may 'take a step back' after a series of inputs. That of course means, that it has to record all of the inputs.

So you have several options here.

  1. Disable the stack function, if you don't really need the 'take a step back' functionality by calling popStack() (by not calling EnableStack() in the builder (see Unit-tests))
  2. Call ClearsStack() more frequently (since your users won't actually believe your software would be able to 'undo' the last 256,000 steps of inputs). Calling this function actually clears the call-stack, thus preventing the overflow (again... see unit-tests and search for 'stack')

let me know if that made sense, Gerald

guFalcon avatar Apr 14 '22 21:04 guFalcon

Thanks Gerald for your quick reply, that is really awesome of you to help me out. I was using the EnableStack and ClearStack and doing a clear for each time around a loop of about 8 substates. I was using a thread sleep and and then calling a trigger in each entry function. Somehow I think this does not allow for the system to clear the stack. I switched out the thread sleeps with a timer and a callback and then the whole system worked.

I do not see the popStack function in the unit tests? And the builder did not allow it in the fluent syntax. Am I missing something?

kjorgensen avatar Apr 14 '22 22:04 kjorgensen