llCastRay a problem in 0.8.2.0

Ask technical support questions about other topics
User avatar
Kayaker Magic
Posts: 354
Joined: Sun Dec 01, 2013 8:40 am
Has thanked: 52 times
Been thanked: 393 times

llCastRay a problem in 0.8.2.0

Post by Kayaker Magic »

I have pointed out the bugs and CPU usage issues of llCastRay before, but despite all these I have still found a few uses for this function.

However, since the upgrade to 0.8.2.0, llCastRay has suddenly become MUCH SLOWER than before. I recall it used to take around 0.025 seconds every time you called it, (which was terrible!) and now it is taking around 0.6 seconds for every call! around 25 times slower!

I recall that there were two versions of llCastRay available, the buggy one and a new one submitted by a developer who wanted a completely working version. But that complete one had an entire copy of ODE inside it and re-built the physics model on every call. So I think there is an option to use the buggy one instead, which just gets the wrong answers without spiking my CPU usage at 200%. I hate to ask for the old bugs back, but this is just too slow to find any uses for it.

Here is a script that measures the time to make a llCastRay call:

Code: Select all

default
{
    state_entry()
    {
        llSay(0, "starting");
        float start=llGetTime();
        integer i;
        for (i=0;i<10;i++)
            list hits=llCastRay(llGetPos(),llGetPos()+<5,5,5>,[RC_DETECT_PHANTOM,FALSE,RC_DATA_FLAGS,RC_GET_ROOT_KEY]);
        llOwnerSay("time per llCastRay call: "+(string)((llGetTime()-start)/10.0));
    }
}
User avatar
Keith Selmes
Posts: 175
Joined: Fri Jan 04, 2013 1:13 pm
Location: Devon, UK
Has thanked: 174 times
Been thanked: 153 times
Contact:

Re: llCastRay a problem in 0.8.2.0

Post by Keith Selmes »

That is bad news. I found llCastRay not very usable, and was expecting good things from the new improved version.
Back to square one then.
User avatar
Oren Hurvitz
Posts: 361
Joined: Sun Dec 23, 2012 8:42 am
Has thanked: 19 times
Been thanked: 499 times
Contact:

Re: llCastRay a problem in 0.8.2.0

Post by Oren Hurvitz »

Hi Kayaker,

We're using the OpenSim default, which is the old (V1) version of llCastRay. So I don't know why it would behave differently from before.

It's possible that the V3 version will actually be faster, and I'd like to test this. What is the exact location you're standing in when you run the timing function above (region + location + direction)?

ETA: V3 may not be as accurate as V1. I tried it with a large sculpted object, and the V3 version of llCastRay is extremely finicky about the ray that it casts: it only detects the object in one particular angle. The V1 version detects it more easily.
These users thanked the author Oren Hurvitz for the post:
Keith Selmes
User avatar
Oren Hurvitz
Posts: 361
Joined: Sun Dec 23, 2012 8:42 am
Has thanked: 19 times
Been thanked: 499 times
Contact:

Re: llCastRay a problem in 0.8.2.0

Post by Oren Hurvitz »

A convenient way to test llCastRay is by attaching an object to the avatar's chest, and then adding the following script to the object. Then I can simply point in the direction that I want to test, and click the object.

Code: Select all

testCast()
{
    vector start = llGetPos();

    rotation rot = llDetectedRot(0);
    vector end = start + <50.0,0,0>*rot;

    llOwnerSay("llCastRay from " + (string)start + " to " + (string)end);

    float startTime = llGetTime();
    list results = llCastRay(start, end, [RC_DETECT_PHANTOM,FALSE, RC_DATA_FLAGS,RC_GET_ROOT_KEY, RC_MAX_HITS,4] );
    float endTime = llGetTime();

    integer hitNum = 0;
    // Handle error conditions here by checking llList2Integer(results, -1) >= 0
    while (hitNum < llList2Integer(results, -1))
    {
        // Stride is 2 because we didn't request normals or link numbers
        key uuid = llList2Key(results, 2*hitNum);

        string name = "Land"; // if (uuid == NULL_KEY)

        if (uuid != NULL_KEY)
            name = llKey2Name(uuid);

        llOwnerSay("   Hit " + name);

        ++hitNum;
    }

    llOwnerSay("Time: " + (string)((endTime-startTime)));
}

 
default
{
    touch_start(integer total_number)
    {
        testCast();
    }
}
These users thanked the author Oren Hurvitz for the post (total 2):
Keith SelmesSerene Jewell
User avatar
Kayaker Magic
Posts: 354
Joined: Sun Dec 01, 2013 8:40 am
Has thanked: 52 times
Been thanked: 393 times

Re: llCastRay a problem in 0.8.2.0

Post by Kayaker Magic »

I put that timing test in a prim and put it anywhere, usually with nothing around it to actually detect with llCastRay. Seems I have been testing it in vars far from the SW quadrant, would that make a difference?

I've tested it in Panthalassa setting the prim down on the dock in front of my store, and in the middle of the the sandbox in Cookie II. I have noticed my guns all have a long delay now (600ms) between the time I click the leftmouse button and when there is any action. This seems to be anywhere in Kitely pointing in any direction.

Yes, llCastRay is full of bugs, but it is not how well it works but how long it takes to do ANYTHING now.

V1 gets false positives for any cast passing through the axis aligned bounding box of any object. So if you take a long thin object and rotate it 45 degrees on two axes then llCastRay sees it as a huge invisible object. In crowded spaces llCastRay sees these bounding boxes everywhere. Best used outdoors.

V1 detects prims that are marked physics type none in builds that have a root prim of physics type prim. I think this is the bounding box problem again, it just puts a large bounding box around the whole object and detects a ray anywhere in that. I have trees with solid trunks but phantom leaves, and llCastRay treats the leaves as solid objects.

V1 takes a HUGE amount of time and CPU resources to work. At least I used to think 25ms was a terribly long time until 0.8.2.0 came along and that timing routine of mine is getting results over 600ms! You pull the trigger on a gun and it fires almost a whole second later!
User avatar
Kayaker Magic
Posts: 354
Joined: Sun Dec 01, 2013 8:40 am
Has thanked: 52 times
Been thanked: 393 times

Re: llCastRay a problem in 0.8.2.0

Post by Kayaker Magic »

I tried my timing test all around the Metaverse with some interesting results:

Location size time (ms)
SL 1x1 10 (lots of variability)
IW 1x1 3 (help from PhysX)
GCG (0.8.2.0) 1x1 30
Wright Plaza 1x1 50 (OSgrid 0.9.0.0)
Paradise 1x1 100 (OSgrid 0.8.3.0)
***the following are all from locations in Kitely*************
Cookie II 2x2 700
Panthalassa 3x3 500
K Welcome Cntr 1x1 50
Test Bed 1x1 3

There seems to be some correlation between the time spent in llCastRay and the size of the varregion, also the number of prims. (Panthalassa broke that hypothesis a bit). It may be that varregions are the place shere llCastRay results are a particular problem. I got the same results anywhere in a varregion, not just the SW quadrant.
User avatar
Oren Hurvitz
Posts: 361
Joined: Sun Dec 23, 2012 8:42 am
Has thanked: 19 times
Been thanked: 499 times
Contact:

Re: llCastRay a problem in 0.8.2.0

Post by Oren Hurvitz »

As I mentioned above, we still use llCastRay v1, since that's the default. But now we also have the ability to switch individual worlds over to llCastRay v3. I've enabled this on Panthalassa; could you please test this and see if it works better, as far as speed and correctness? Let me know when (and if) you want to switch back to v1.
User avatar
Kayaker Magic
Posts: 354
Joined: Sun Dec 01, 2013 8:40 am
Has thanked: 52 times
Been thanked: 393 times

Re: llCastRay a problem in 0.8.2.0

Post by Kayaker Magic »

Testing the V3 llCastRay on Panthalassa.

Timing:
V3 has very nice low times! I never saw it take more than 3ms to run, averaging closer to 2ms and often less than that! Better than InWorldz with PhysX, better than SL!

Correctness:
The V1 bug of detecting anywhere in the axis aligned bounding box of a prim, this is fixed in V3! llCastRay doesn't seem to hit invisible objects everywhere in crowded areas.

I tried to test the ability to NOT detect "physics type" none child prims on non-phantom root objects. V3 appears to fail, incorrectly returning hits on physics:none leaves on non-phantom trees. But before I could finish testing, somehow my script got set to not running! I checked running and continued testing, but after a while the script stopped working again. I checked and this time it was still set to running, but I could not reset the script. I cannot re-compile the script. My avater keeps getting stuck in animation poses. Ilan IM'ed me in the middle of all this and told me that my CPU use had spiked and I should undo whatever I had done. After a while I started getting "unable to upload ... Please try again later" messages.

I am not doing anything different, my "test script" is my M1 Garand rifle, because because it is easy to aim and has a dialog option to display the name of the object llCastray detected.

I added an additional printout to the script, telling me the result of the llCastRay call and discovered that quite often it fails to detect terrain, then does a few meters to the side. I also think that lLCastRay is detecting the bullets left behind by the gun which are phantom and should not be detected with the options I am requesting:
list hit = llCastRay(start,end,[RC_DETECT_PHANTOM,FALSE,RC_DATA_FLAGS,RC_GET_ROOT_KEY]);

So calling V3 llCastRay seems to work a little better than V1, but then becomes unstable and starts messing up the sim.
I will try again later, leave it running on Panthalassa for now.
User avatar
Kayaker Magic
Posts: 354
Joined: Sun Dec 01, 2013 8:40 am
Has thanked: 52 times
Been thanked: 393 times

Re: llCastRay a problem in 0.8.2.0

Post by Kayaker Magic »

After complying with Ilan's request to reset Panthalassa, I did a little more testing (keeping my eye on the CPU usage this time)
All the problems with scripts halting, unable to compile, unable to save, were fixed by the reset. (I just logged out and waited for the world to get shut down, then logged back in).
1) I verified that V3 llCastRay does incorrectly detect "physics type none" parts on objects with root prim "physics type prim".
2) In fact, V3 incorrectly detects any prim that is marked Phantom. (V1 does not have this problem, I went to Test Bed to verify this)

So two of the 3 problems I knew of with llCastRay are fixed in V3 (time taken and axis aligned bounding box), one is not fixed (phantom parts on non-phantom objects) but there are two new problems (sees phantop objects and crashes the sim).

I have not seen the CPU usage go up again since the reset. Please leave V3 llCastRay running on Panthalassa. I will test it more when I can and see if I can find what causes the runaway CPU usage. If that was fixed, I would say V3 was worth switching to! I'll try to attend the next OpenSim Dev meeting and ask about lLCastRay and the different versions. I asked them last week about long llCastRay times and none of the devs who were there had any knowledge of llCastRay.
These users thanked the author Kayaker Magic for the post:
Selby Evans
User avatar
Ilan Tochner
Posts: 6504
Joined: Sun Dec 23, 2012 8:44 am
Has thanked: 4943 times
Been thanked: 4455 times
Contact:

Re: llCastRay a problem in 0.8.2.0

Post by Ilan Tochner »

Thank you Kayaker. Please continue to keep us updated.
Post Reply