Getting a SystemStackError?

Hi - sorry for making another thread on such short notice, but I've been having a problem with the "Stack too deep" error, and I don't know how long I've had it, because I've been testing out battle stuff for so long - that the error always happens when I start a new game. But doesn't happen when I try out test fighting during troop battles.

From what I understand from google, the cause is a duplicate script - but I do not have that. I've checked everything, deleted all my common events, extra scripts that I wrote, and systematically went and deleted borrowed scripts one by one until the game worked.

And I do feel like I singled the issue to one script that's doing it since deleting only it will let the game run - but the script's always been fine before for me and I think it's driving me crazy that the game is just not working anymore. And I really feel like I have no choice but to scrap it even though I really need it and I feel like it's got to be something else messing with the script.

Is there anyway to know for sure what I'm doing wrong here - so I can absolutely make sure that the only way to fix it is by deleting the script even if it would ruin things incredibly hard for me and the game?
There are two common causes of the stack error too deep bug:

1: Duplicate scripts. Usually one of them is on an invisible line that was forgotten about when this happens, or under the wrong name.

2: Code that keeps calling itself until the engine gives up due to no more memory in the stack (I think someone said this usually happens on the 100th call of a function but don't quote me on that). This can happen depending on how scripts are set up, and can usually be fixed by putting your scripts in a different order.

I'm thinking it's probably the 2nd myself, as if it is now occurring on new game, then you got something that is creating an infinite loop until the engine runs out of memory and throws that error. It could be a new script you added, or it could be that somewhere sometime you accidentally made a small change to the script giving the error (deleted a }, added an extra {, little things like that), and now it is doing this.

As for why battle test doesn't hit it, battle test only loads what it needs. So odds are it is not a battle related script, or at least one that battle test needed.

If you can't find the error with that, you may wish to find the backtrace script by Hime and install it and see what error output it dumps out. That can go a long way to finding the cause.
You wrote all this down, yet didn't include the name of the script which causes it? Why would(n't) you do that? 😀

Having duplicate scripts are not the only thing that can cause a stack error.
Getting into infinite loop from calling the same method inside the same method (also called recursive methods if they are intentionally designed to work like that) can cause it too, although this is very rare unless something is coded very wrong and/or not tested with longer recursion occurrences.

I was the one who thought the max recursion was 100 tries, but I looked it up since then, because I managed to make a recursive method which hit the limit (and it was after the ~500th loop), and it turns out that it depends on the maximum allowed memory for recursion. I couldn't change that limit no matter how I tried, so I just left it at that (making it without recursive method calls made the code longer, but at least it worked with infinite loops that way).

In any case, knowing which script causes it for you can give us a pretty good idea when and from where it happens.

The backtracer won't help here, since it can't backtrace something that never finishes. At least it didn't help me when I got this issue in my code.
For this error, the error message doesn't say what script is causing the problem.
Well the reason why I didn't mention the script - is because I made another thread about the script that seems to be the one causing the stack issue and I was worried this would be shut down before I got any help on this stacking issue. But the script that seems to fix the game when deleted, is Victor's State Graphic script - which is kind of vital to my game for visual stuff. But I really haven't tested the game outside of troop fights so I had no idea what was going on with the actual game itself.

But I know I have tested the game before to play with a few maps with the script up and working - and I have another test project that is working fine with it and shares several other scripts with each other. So I don't think the script is causing the issue by itself or at least I hope it's not.

So far I've tried deleting every script that I've installed afterwards - but the error only stops when I delete that script.

So I feel like my best option now, is to copy the project, delete everything but the victor scripts and copy/paste in everything other script one by one until the game errors and then maybe I could find something to work with from there?
Sounds like the error is the state graphics are calling themselves too often, and causing a crash. This happens in a lot of scripts if you use a remove by restriction condition for a state, and then try to make it a passive state. Those two do not combine well, the script gets confused (as it is trying to add and remove the state at the same time), loops forever and crashes.

Check if you have any states you start the game with, or any states with remove by restriction. Those might be the issue.
What I do when trying to narrow down a fault is to copy the game project then delete a few scripts at a time until I narrow down which one(s) it might be. But from your situation it sounds like you need to make a new project and copy your scripts over one by one, then I would advise to make a backup/copy and start removing scripts from that if the issue is still there.
Well, I've already found the script causing the problems. I've deleted everything but that script - and I still get the error when running. But I am building up the game from scratch - though I'm not remaking maps/events again because I know the game is probably still going to get messed up.

Sounds like the error is the state graphics are calling themselves too often, and causing a crash. This happens in a lot of scripts if you use a remove by restriction condition for a state, and then try to make it a passive state. Those two do not combine well, the script gets confused (as it is trying to add and remove the state at the same time), loops forever and crashes.

Check if you have any states you start the game with, or any states with remove by restriction. Those might be the issue.

But I'll probably do this first - I use the state changes as a way to change sprites, and that I do use starting states as a way to plug in a bunch of traits at once, and then have them be removable.

Like having a hairy snow enemy - who gets it's warmth from a "winter coat state" that can get removed in battle, making it weak to cold when it's removed. And that it does apply to characters too, by giving them element stuff - that can be removed mid battle or just altered somewhere else.

//Edit:
Okay - so I went back to my older save, deleted every note tag on my states (which triggers the change) and the game seems to run fine, except I lose the sprite switching completely - which is just as bad as deleting the script.
You may wish to post how you are using it to change sprites, as odds are that is what is causing the error. I assume it is some sort of common event?
Yeah, that would help.

But as I was writing this out I did go back and re-check my states, and it looked like I did set a few of the sprite states, to have an auto-removal time switched on. And I tried this on the original and the stack error occurred still - but on one of the back ups, which is identical - worked fine, and seems back to normal strangely?

I think I remember changing the maximum states awhile ago and the state changing ones got deleted - and I remember panicking a bit that they weren't working so I might have flipped them on then before I realized the script was calling states that weren't there and forgot I left the conditional water running.

And then I just hadn't tested the main game until yesterday where it started causing problems.

But the way the sprite changing works is by calling a method in the damage formula box called "act(a,b)".
The method is a bit of script that looks like this:
Code:
def act(a,b)
  a.add_state(28)
  if a.state?(40);a.add_state(41);end;
  b.add_state(31)
  if b.state?(40);a.add_state(42);end;
end
And I guess to explain it - a's are the attack sprites, the state check underneath is a check to see if the actor has a "toad" like status. B is the same, except it changes the enemies sprites.

So I don't want to jinx it - but I guess for right now, it seems to be working? Though I really don't know if it's worth the hassle to keep things running like this and maybe I'd be better off finding an easier way to do this.

But anyways, the game seems okayish now - so thanks!

Original thread: https://forums.rpgmakerweb.com/threads/getting-a-systemstackerror.91042/