What is a "stack dump" and what does it mean for my game.
There seems to be a lot of inaccurate information going around about what a "Stack Dump" is, what it means and what can be done to avoid them.
Short explanation:
A stack dump is what is written to the Papyrus log file whenever the "stack" used by the game to track all the actively running scripts is full and no additional scripts can be run.
It is an occurrence that means your game didn't do something or multiple somethings it should have done at the time they were expected to occur and as a result your game should be considered unstable and in an unknown state or more directly, toasted. You cannot rely on anything past the point of a stack dump because you cannot know what did not occur and what the failure means for your game. You can load a save from before the Stack Dump occurred and try to avoid repeating the situation that caused the stack dump to occur.
How do I prevent Stack Dumps from happening?
The worst thing about Stack Dumps is that the game gives no indication other than perhaps a stutter or FPS loss that one occurred, without examining your Papyrus Log to hunt for a Stack Dump you may be unaware they occurred and if you don't have Papyrus logging turned on you can't even use the log to know if one occurred.
What you can do to prevent Stack Dumps from happening is not run the sort of mods which are known to cause them.
Long Explanation:
What is a Stack Dump?
A stack dump occurs when there are so many scripts actively running at once that the "stack" used to keep track of them overflows.
In simpler terms it means when the game went to start another script or script instance there was no room in the list used by the game to track those scripts so the script was not run. Until a running script ends all requests for new scripts to start will also cause additional stack dumps occurrences to be logged increasing the overhead in the game and therefore making it less likely a script will be given time by the game to finish.
What does having a Stack Dump occur in my game mean for that game?
A Stack Dump caused by one mod can cause a script or multiple scripts that should have run for the mod causing the Stack Dump, other mods or the standard game to not get run causing problems in those other mods or the game because they expect the script to have performed some action(s) that didn't occur. The exact problems caused by any given Stack Dump are highly dependent on what scripts did not get run but the log only tells you what scripts were running, not which script(s) did not run.
That means some script which was intended to run and perform some action didn't run when expected, the game does seem to keep track of what scripts did not run and will eventually run the skipped scripts but by the time the script is finally allowed to run it may be far too late. Often that can have no noticeable effect on the game because there are a multitude of scripts running that do very little of note so if they don't run you may not notice. However if it was a critical script for the game or a mod that didn't run and update a quest you can have unexpected breakage of that quest, and often that won't show up for a while.
By that action (script not running) Stack Dumps therefore create situations that look like bugs in the game and in mods.
There is no notification in game that a stack dump has occurred which makes this more problematic as well since most people have no idea anything bad happened and therefore they play on oblivious to the damage instead of jumping back to their last save and avoiding the problem.
Early after the release of Skyrim the most common cause of stack dumps was using the "RegisterForUpdate" call with a very short interval so any time the script took longer to complete than the interval to the next update you'd get a cascade where more and more of the events would get started but because of the number of them all trying to accomplish their task even more of them would not complete until the game completely overloaded. That was fixed by people switching to using the RegisterForSingleUpdate call instead where the update processing code would simply call for the next update as the last thing to be done before exiting so there would never be more than one outstanding call.
Currently the most common cause for stack dumps is the use of "Cloaking spells". The documentation for the CK shows how to create and use cloaking spells as a way of dynamically attaching a script to NPCs without having to mod every NPC in the game to have that script available and a great many mod authors have used that technique in their mods. A cloaking spell is essentially an area effect spell (usually hidden) which is cast in a circle around the target (usually the player) that attaches a script to everything that the spell is designed to effect which is usually NPCs but can be any kind of object. The problem with cloaking spells is that there is a unique instance of that script attached to each item selected by the cloaking spell so the more objects or NPCs selected the more likely it is you'll bump into a Stack Dump situation.
Now add several mods which all perform cloaking spells continuously some even performing multiple cloaking spells at once (Beeing Female for example) and you have a greatly increased chance of having a Stack Dump occur. Now add a mod or two like the Populated Cities mod which adds a lot more NPCs to areas and combine that with mods performing cloaking spells on NPCs and once again you've really increased the likelihood you'll get them.
I researched stack dumps extensively when I came across them several years ago caused by the Sexlab Submit mod. It used cloaking spells to select NPCs around the player but didn't use any of the options provided to limit the selected NPCs to just those wanted. For instance it has a feature to have any guard seeing you having sex in public interrupt you. But instead of casting the cloak spell on just guards and limiting it further to guards that were in a position where they could see you it cast the spell on all NPCs and then threw out those who weren't guards and then checked of they could see you. Worse yet, that was an optional feature but the check to see of the option was enabled was also made in the script running on each NPC instead of in the script that triggered the spell in the first place so whether you enabled that option or not the spell was always running (it also always ran whether you were having sex or not). Needless to say, it triggered a lot of stack dumps.
The original Sexlab Aroused mod also used a cloaking spell, the replacement of that cloaking spell in the Sexlab Aroused Redux mod made a huge improvement in the performance of that mod and removed it from the list of mods which frequently cause stack dumps.
What was done in Sexlab Aroused was the cloaking spell was replaced by a silent Quest which can be used to fill quest aliases on that quest but only one script instance is generated which then iterates through all the selected NPCs or items.
Now there is also some confusion about what is or is not a stack dump, if a script errors out it will show the stack for that single script but that is not a stack dump. A stack dump is an action where the game dumps the stack of all the running scripts into the log at once and will repeat that entire dump sequence for every single script that fails to start so if a cloaking spell were to select twenty NPCs but there was only room on the stack for fifteen additional script instances you would see five entire stack dumps getting logged (one for each script instance that didn't run at that time because of the lack of resources) which can cause the log to balloon to enormous sizes in a hurry.
When you see a stack dump in your log, find the first occurrence and were it starts and ends then look to see what script or scripts are listed in the dump most often, the mods those scripts belong to are your problem mods. Once you know what mods are causing the problem you can decide what to do with them individually, sometimes the mod isn't really important and you can eliminate it, sometimes the option of that mod causing the stack dump can be turned off because it's not a vital part of the mod and sometimes you have to give up a mod that sounds fun but is just a quick trip to an unstable and unplayable game.
I hope this explains why you got this problem and how you can fix or avoid it.
Note: Previously I thought that those scripts that didn't run would never get run but it has been pointed out that the game does seem to manage to queue them and will eventually run them if it ever gets the chance to catch up. That still makes the game unstable and can cause timing window issues and induce what look like bugs into mods that would have functioned perfectly except for the interference of the mod causing the stack dumps.
10 Comments
Recommended Comments