System Stack Error

Hi guys, I have a scripting problem I can't resolve.

I'm using Theo's sideview battle system, and have implemented a combo system where the player can chain together various attacks.

However, reaching a combo of 16 hits will crash the game with a 'system stack error - stack level too deep'.

I used Hime's stack debugger and it directed me to line 1839 of Theo's 'Implementation' script, that deals with fiber?

Here is a link to a fresh project that replicates the error.  https://www.dropbox.com/s/qyxesuuvahvdilx/HimeStack.exe?dl=0

To trigger the error, use the Crimson thorn skill at full TP and reach a combo of 16.

The prompts are xbox pad by default, they correspond to keyboard like this: A(prompt) = D Y(prompt) = A

The script for the move is in 'sequences'.

I left a message on Theo's blog but I noticed he hadn't replied to bug reports for a while.  If anyone knows him, please let him know of this thread.

Please help me if you can, it would be greatly appreciated.
Sorry, but I could not reproduce the error, with a quite a stupid issue.

When I use Crimson Thorns, letter A shows up.

I tried spamming both A and :A buttons, but none of them worked.

Could you please explain it how to use this system?

I'm not really into reading the whole script documentation right now...
That error message usually indicates you've got two scripts that are both aliasing the same class/method using the same name.


Commonly it's because a script has been put into your project twice. Look through all script slots, including those without names, and make sure you only have ONE script in each slot (that it hasn't been pasted twice into the same slot), and that no two slots have the same script.
Sorry, but I could not reproduce the error, with a quite a stupid issue.

When I use Crimson Thorns, letter A shows up.

I tried spamming both A and :A buttons, but none of them worked.

Could you please explain it how to use this system?

I'm not really into reading the whole script documentation right now...
Hi, Kocka, the prompts are xbox pad by default.

They correspond to D and A on the keyboard.  A(prompt) = D  Y(prompt) = A

Thank you for helping!

That error message usually indicates you've got two scripts that are both aliasing the same class/method using the same name.

Commonly it's because a script has been put into your project twice. Look through all script slots, including those without names, and make sure you only have ONE script in each slot (that it hasn't been pasted twice into the same slot), and that no two slots have the same script.
Yes, I researched and that seems the most common source of the error.  However I'm pretty sure I dont have duplicates.  I passed the test project to Hime and multiple copies didnt seem to be the issue.  I mean, I'm wondering if the method is defined by two different scripts?  But wouldn't that crash it right away?  Thanks for the suggestions!
It can also be an infinite loop...
It can also be an infinite loop...
Ah that's interesting Engr, since I coded two sequences that chain together as long as the user has TP for it.

It's not infinite though for that very reason, and I find it strange why a chain of 16 is the limit.
Not really sure up to what is considered "infinite" by RGSS3... I was just thinking it might be one of the possible reasons as I've experienced it in the past. Normally the programs just hang up if there's an infinite loop but sometime in the past I got that error and realized it was an infinite loop of some kind.
Yes, you see that's why I actually split the attack into two sequences that chain between each other, rather than just one sequence that chains into itself repeatedly, I was worried about the loop thing.

I discovered that stripping away all the code apart from the timed hits and damage lines allows the chain to get up to 25 before crashing.  So it's weird.
Well, if it's calling each other then it might really be going into a stack...

So like

Code:
$stack = 0def a  benddef b  $stack += 1  if $stack < 15    a  endend#So it basically calls a which calls b inside of a which runs a again which then calls b again inside so it forms a deep stack#a# b#  a#   b#    a# and so on#the very first a call is still waiting for response in this case#so it will need to finish the deepest stack before the upper stacks can get their responses and finish execution
It might be good to see if you can make it iterate without producing a stack. I haven't looked at the file itself so...
I'm not a coder but I understand what you're saying about a not being resolved before b is called.

Could you take a look at the file please?  I would greatly appreciate it! <3
I'll try... this error is one of those things that don't give an obvious source. 🙂
Thank you.  Let me know if you need any clarification about Theo's battle system.
Did you only test it during battle test and not really in-game?


PS: Sadly, there are far too many scripts in there that I don't have experience in... It doesn't even seem to have Hime's debugger which you used to pinpoint the error into the line.
I don't think sequences are the problem, since those sequences can end anytime, with just you not pressing any button.

I think the problem is that Theo's script does something in background that makes his system limited to only 16 combos.

Can you please post here the direct link to Hime's debugger, since I remember I could not access it last time (I think it was Dropbox error or something...)
Did you only test it during battle test and not really in-game?

PS: Sadly, there are far too many scripts in there that I don't have experience in... It doesn't even seem to have Hime's debugger which you used to pinpoint the error into the line.
I tested it in game too, this was for my IGMC 2015 game Kazimir.  

I don't think sequences are the problem, since those sequences can end anytime, with just you not pressing any button.

I think the problem is that Theo's script does something in background that makes his system limited to only 16 combos.

Can you please post here the direct link to Hime's debugger, since I remember I could not access it last time (I think it was Dropbox error or something...)
Sure: http://himeworks.com/redirect.php?type=script&name=System_Stack_Debugger

Unfortunately it only gives you one line of info though, about line 1839 of the Implementation script.
Hmmmm.... the problem is very strange....

However, Theo is constantly making new Fibers when battler hits the enemy, and then puts them into $game_temp.actors_fiber[actor_id], and every Fiber has

tsbs_main_fiber functions in it.

I'm not really sure how this can cause SystemStackError...
yes it can - you shouldn't forget what a system stack really is.


All stacks are limited, it's only that this limit is usually so high, that only unintended iterations can break it - like what is happening with two identical scripts.


But if the program has functions that intentionally call themselves, and is using stack for keeping track, then it will cause the stack to overflow.


And that is what the original message basically says - it prevents a stack overflow by canceling further access (otherwise a stack overflow could be used for injection-type attacks).


However, I don't know enough of ruby or that script to find the cause - and if it's an intentional iteration, then the bugfix won't be a few lines only...
I know of that, but nothing here is running in background and infinitely.

Theo used something like :

def insert_fiber(fiber)  if actor?    $game_temp.actors_fiber[id] = fiber  else    ...  endendand called it with parameter Fiber.new { tsbs_main_fiber }

Are other Fibers destroyed, and not running in background anymore, or using fiber = on the currently running fiber can cause that Fiber is still running in background?

Note that tsbs_main_fiber is an infinite function, that means it has something like :

Code:
def tsbs_main_fiber  # some stuff  loop do    # some stuff  endend
Not a fix but a cap to the combos at 16 so it will prevent any crashes:

Code:
class Game_Battler < Game_BattlerBase  # --------------------------------------------------------------------------  # New method : Setup timed hit system (BETA) [:timed_hit,]  # Will expand it later. I hope ~  # --------------------------------------------------------------------------  alias fix_setup_timed_hit setup_timed_hit  def setup_timed_hit    return if SceneManager.scene.damage.hits >= 16    fix_setup_timed_hit  endend class DamageResults  # --------------------------------------------------------------------------  # * Hits  # --------------------------------------------------------------------------  def hits    @hit_count  endend

Original thread: https://forums.rpgmakerweb.com/threads/system-stack-error.45587/