I've got a script, that fires when a player dies.
It then calls a nwnx function, that duplicates the area (to make a spookier version of the place they die in - to be a ghost plane of sorts.
In order to accomplish this, several things need to be done
1. Area duplicated - Check (works fine)
2. Area Name, Fog, Tag Changed - Check (ensures no porting, or scripts referenceing this area by accident, also makes the place look like the after life.)
3. Loop through the area's objects, and depending on the type of object do certain things - Works 80-90% of the time.
The issue is that when it is looping through the objects, occasionally, it gets to an object, and then the server crashes.
I have reporting done in my loop, to report what object it was on, and there doesnt seem to be any pattern.
Just randomly crashes within this loop.
object oObj = GetFirstObjectInArea(oArea);
while(oObj != OBJECT_INVALID)
{
switch(GetObjectType(oObj))
{
case OBJECT_TYPE_PLACEABLE:
SetPlotFlag(oObj,FALSE);
DestroyObject(oObj);
case OBJECT_TYPE_DOOR:
//Some nwnx functions here that change door script and tags
case OBJECT_TYPE_WAYPOINT:
//Destroy Waypoints too
case OBJECT_TYPE_TRIGGER:
//Destroy triggers
case OBJECT_TYPE_ENCOUNTERS:
//Destroy encounters to prevent living monsters, appearing in the afterlife.
case OBJECT_TYPE_ITEM:
//No painted items from toolset should appear in this realm, so we desotry these too
case OBJECT_TYPE_CREATURE:
//No painted creatures should appear here either - destroy
}
oObj = GetNextObjectInArea(oArea);
}
Ok, so you can see kind what im doing above.
This is all pseudo-code.
But can anyone see any reason why a crash would be occuring within this loop?
I mean - is there any special rules required by DestroyObject when used in a loop?
Eg - Does it affect the collection of objects, in such a way that indexes can be lost, causing exceptions etc?
I've tried this multiple ways.
Most recent code has got a DelayCommand(0.3,xxxxxx);
On destroy object calls, to ensure that enough time is given for the PlotFlag to disappear, and to allow the loop to continue on without being blocked.
I've also got code that 'Disables the encounter' immediately, and then destroys it 0.3-0.6 seconds later, just to ensure that the encounter doesnt fire if the player gets into the area, before the destroy function has finished.
At the moment, I dont know what object, if any, is responsible.
seems to occur randomly, in different areas, and not 100% reproducable.