In my mod, I refwalk through the MISC items in a cell and, if they're truly junk, transfer them to a box in the player's house. Occasionally, after a lot of play, when I enter an area filled with a lot of junk (so far, the Arlington(?) Library and Dukov's place), the game will crash about the time the script should start running. It's not necessarily reproducible (i.e., when I load up a save game from just before walking through the door, it doesn't crash). I can't figure out what's wrong. My current possibilities are that 1) there's so much junk in the cell that all the sudden processing after lots of previous play svcks the remaining memory or other resources out of the game and crashes it, 2) there's so much junk in the cell that my loop can't get through it all before the frame changes and a reference goes null in the middle of use, or 3) there's so much junk in the area that trying to process it all while the cell is loading (even with a 5 second delay) svcks all the memory/resources out of the game and it crashes. Are there other things I should do in this script to try to prevent crashing? Is there some way to figure out what's causing the crashes (since it's not reliably reproducible, and there are bajillions of pieces of junk out there, I can't just turn on my PrintToConsole statements (removed from the code, below) and dump everything to a text file with SCOF)?
ScriptName DALCOJunkOMaticScript;This script is attached to the DALCOJunkOMatic device in the player's inventory. The only difference between this script and the one with the 2 is the box things go in.;It looks for all the MISC items in a cell, and checks for ownership and true junk status;It then activates it delete it from the cell and to transfer one piece to the player's inventory (a fault with activate - it should move the whole stack).;It then does an AddItem for that item directly to the Box in the player's house for all the items in the stack. Then, it removes the 1 piece brought in by Activate.float fTimershort bRunItshort iSizeOfStackreference rBaseObjectreference rOwnerreference rPieceOfMiscBegin OnEquipif GetFOSEVersion ; checks to see if FOSE is present (required) set bRunIt to 1 ;Failsafe Variable Initializations set fTimer to 0 set iSizeOfStack to 1else ;If FOSE isn't running, display a warning and set things up to quit set bRunIt to 0 ShowMessage DALCOJOMFoseWarningMessageendif ;done with FOSE existence checkEndBegin GameModeif bRunIt if (fTimer < 5) ; Want the big stuff to run only periodically. So, if less than five seconds have passed, just increment the timer set fTimer to fTimer + GetSecondsPassed else ; This is the main stuff that run every 5 seconds set rPieceOfMisc to GetFirstRef 31 0 0 ; Finds the first reference in the current cell of MISC type ("31") Label 10 ; this is the start of the loop to grab all MISC items in the cell if (rPieceOfMisc) ; if it found something to process -- now see if it's not mine already set rOwner to rPieceOfMisc.GetOwner if (rOwner != player) ; Only look at things that don't belong to me if (rPieceOfMisc.IsInList DALJunkItemsList) ; if it's in this list, it's junk set iSizeOfStack to rPieceOfMisc.GetRefCount ; find out how many items are being pointed to rPieceOfMisc.SetOwnership ; since it's junk (i.e., mostly worthless), set it to me so I can take it set rBaseObject to rPieceOfMisc.GetBaseObject ; for use after Activate on the ref rPieceOfMisc.Activate player ; removes the item from the cell and adds one piece to player's inventory DALCOMiscItemsBox.AddItem rBaseObject iSizeOfStack 1 ; add all of the item to a container in the player's home (without a message) player.RemoveItem rBaseObject 1 1 ; removes the one item from the Activate statement endif endif set rPieceOfMisc to Apple ; Prevent "apple" bug set rPieceOfMisc to GetNextRef ; get the next reference in the current cell of MISC type ("31") and repeat Goto 10 endif set fTimer to 0 ; we've done our processing for this clock cycle, so set the timer back to 0 endifendifEndBegin OnUnequipset bRunIt to 0End