Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0008708opensim[REGION] OpenSim Corepublic2020-05-26 02:072020-05-26 06:19
Assigned Tomewtwo0641 
PlatformOSOS Version
Product Version 
Target VersionFixed in Versionmaster (dev code) 
Summary0008708: OpenSim crashes if a new agent is connecting and their ScenePrescenceState can not be set
DescriptionAs of master, whenever a new ScenePresence is made while ScenePresence.Dispose() is being called it results in OpenSim crashing due to being unable to set ScenePrescenceState; which in itself throws an exception in ScenePresenceStateMachine.SetState() if setting the state was unsuccessful.

I have added a patch that avoids the issue. It does LifecycleState = ScenePresenceState.Removed; in Dispose() in a try/catch to prevent crash if it does happen.

Exception on crash:

  Message=Scene presence Test NPC is not allowed to move from state Running to new state Removed in Test Region
   at OpenSim.Region.Framework.Scenes.ScenePresenceStateMachine.SetState(ScenePresenceState newState)
   at OpenSim.Region.Framework.Scenes.ScenePresence.Dispose(Boolean disposing)
   at OpenSim.Region.Framework.Scenes.ScenePresence.Finalize()
Steps To Reproduce1. Use the script in Additional Information in conjunction with an NPC notecard. (Change string npcNote = "put npc notecard name here"; to your notecard name)

2. Once the object is set up with the NPC type "start" (sans quotes) in chat to make the NPC rez if it hadn't already rezzed yet.

3. Shut down OpenSim
    a. The result should be a crash towards the end of shutdown.

4. If you don't get a crash after Step 3, then try making a few copies of the NPC object (I tested with 3 of these NPCs out which resulted in a crash).
    a. Wouldn't hurt to give the NPCs some attachments, possibly scripted attachments for the purpose of triggering this issue.
Additional Information//Script to test with
//NOTE: This is my version of the NPC Persist inspired by the script found here [^] although it is likely that the original script will cause the same issue because it has the same end result, rezzing a new NPC if the original disappears for whatever reason. Having said that, I've not tested that particular script yet for this issue.

string firstname = "Test";
string lastname = "NPC";

//This should be the only thing needed to be changed manually to test issue
string npcNote = "put npc notecard name here";

list anims = []; // List animations to play at random here

integer sitOnThisObj = TRUE;

integer npcPersist = TRUE;

key npc = NULL_KEY;
float timerRefresh = 1.0;
vector offset = <0.5, 0.0, 0.0>;

string chatInit;
string chatKill;
string chatStillHere;

    // Chat set up is done in its own function so that variables
    // can be used thus avoiding Error CS0236.
    chatInit = firstname + " " + lastname + ", at your service.";
    chatKill = "I'm leaving.";
    chatStillHere = "I'm already here.";
    // Setup and rez the NPC.
    //An NPC matching the UUID stored in the object
    //description already exists, so just retrieve the UUID.
    if (npcExists())
        npc = (key)llGetObjectDesc();
    // Create NPC if one doesn't exist
    else if (!npcExists())
    llListen(0, "", NULL_KEY, "");

integer npcExists()
    key tempKey = (key)llGetObjectDesc();
    if(llGetAgentSize(tempKey) != ZERO_VECTOR && tempKey != NULL_KEY)
        return TRUE;
        return FALSE;

        llOwnerSay("Not creating NPC because npcPersist = FALSE");
    //Check that npc notecard exists
    if(llGetInventoryType(npcNote) == -1)
        llOwnerSay("Can not find NPC note '" + npcNote + "'");
    // Create a new instance of the NPC, set flag for persistance checks,
    // record the UUID in the object's description, and set starting rotation.
    // NPC rotation and location are inherited from the controlling object with an offset.
    npc = osNpcCreate(firstname, lastname, llGetPos() + offset, npcNote);
    osNpcSetRot(npc, llGetRot() * (llEuler2Rot(<0, 0, 90> * DEG_TO_RAD)));
    osNpcSay(npc, chatInit);
    if(llGetListLength(anims) > 0)
        string anim = llList2String(anims, (integer)llFrand(llGetListLength(anims)));
        osAvatarPlayAnimation(npc, anim);
    // Sit on this object if required
        osNpcSit(npc, llGetKey(), OS_NPC_SIT_NOW);
    // Set up persistance timer
killNpc(integer notify)
        osNpcSay(npc, chatKill);
    //Remove NPC
    //Null the keys
    npc = NULL_KEY;

    changed(integer change)
        if(change & CHANGED_REGION_START)
        if (!npcExists())
    listen(integer channel, string name, key id, string msg)
        // Kill the NPC and set a flag so it stays off.
        if (llToLower(msg) == "kill")
            npcPersist = FALSE;
        // Create a new NPC
        else if (llToLower(msg) == "start" && !npcExists())
            npcPersist = TRUE;
        // NPC still exists
        else if (llToLower(msg) == "start" && npcExists())
            osNpcSay(npc, chatStillHere);
TagsNo tags attached.
Git Revision or version number
Run Mode Grid (Multiple Regions per Sim)
Physics EngineubODE
Script EngineYEngine
Environment.NET / Windows64
Mono VersionNone
Attached Filespatch file icon 0001-Avoid-crashing-OpenSim-in-certain-circumstances-such.patch [^] (1,551 bytes) 2020-05-26 02:07 [Show Content]

- Relationships

-  Notes
UbitUmarov (administrator)
2020-05-26 04:46

thanks for adding the error message, that made it a lot more clear
the issue is just bad assumptions on the ScenePresenceStateMachine

that is old 0.8x code i just keep considering removing..
I do keep it, because it is a good idea that just never worked right
most 0.92 code uses presence state flags to actually do the control

So thanks but not using your patch
i also don't fancy the idea of try{} inside dispose
UbitUmarov (administrator)
2020-05-26 05:24

no point even on updating something about to be deleted ( we hope)
pushed change
mewtwo0641 (reporter)
2020-05-26 06:19

Understandable :) I just wasn't sure if it was necessary to have that state set or not, so I just wrapped it in a try catch to stop the crashes.

Tested your change and seems to be working fine. Did startup and shutdown of OS a few times with the test script running and no crashes.

Thank you!

- Issue History
Date Modified Username Field Change
2020-05-26 02:07 mewtwo0641 New Issue
2020-05-26 02:07 mewtwo0641 File Added: 0001-Avoid-crashing-OpenSim-in-certain-circumstances-such.patch
2020-05-26 02:07 mewtwo0641 Status new => patch included
2020-05-26 02:09 mewtwo0641 Description Updated View Revisions
2020-05-26 04:40 mewtwo0641 Description Updated View Revisions
2020-05-26 04:46 UbitUmarov Note Added: 0036510
2020-05-26 05:24 UbitUmarov Note Added: 0036511
2020-05-26 06:19 mewtwo0641 Note Added: 0036512
2020-05-26 06:19 mewtwo0641 Status patch included => resolved
2020-05-26 06:19 mewtwo0641 Fixed in Version => master (dev code)
2020-05-26 06:19 mewtwo0641 Resolution open => fixed
2020-05-26 06:19 mewtwo0641 Assigned To => mewtwo0641

Copyright © 2000 - 2012 MantisBT Group
Powered by Mantis Bugtracker