Difference between revisions of "LSL Errors"

From Second Life Wiki
Jump to navigation Jump to search
m (ouch, for the sake of the nearby table-of-contents style capitalise the demo script section heading differently)
m (Replaced <source> with <syntaxhighlight>)
 
(8 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{LSL Header}}
{{LSL Header|ml=3}}


==Run-time error messages==
==Run-time error messages==
Line 7: Line 7:
===Script run-time error: Heap Error===
===Script run-time error: Heap Error===


Don't be evil. For example, don't return a list of one entry that is the result of a routine that returns no result.
Don't speak nonsense. For example, don't return a list of one entry that is the result of a routine that returns no result.


===Script run-time error: Lists may not contain lists===
===Script run-time error: Lists may not contain lists===
Line 16: Line 16:


Float divided by zero, integer divided by zero, etc.
Float divided by zero, integer divided by zero, etc.
See {{LSLGC|Error/Math}} for functions that can generate this.


===Script run-time error: Stack-Heap Collision===
===Script run-time error: Stack-Heap Collision===


The Stack has collided with the Bytecode or the Heap.
The Stack has collided with the Bytecode or the Heap. (The script has run out of memory)


Each script runs inside 16 KiB of memory divided out among Bytecode, Stack, and Heap.
In [[LSO]] each script runs inside 16 KiB of memory divided out among Bytecode, Stack, and Heap.


You can cause collision by compiling too much script, which produces too much Bytecode. The script compiles and saves successfully, but when you rez an object containing the script, the script crashes, immediately or while running.
You can cause collision by compiling too much script, which produces too much Bytecode. The script compiles and saves successfully, but when you rez an object containing the script, the script crashes, immediately or while running.


See [[llGetFreeMemory]].
See [[llGetFreeMemory]] and {{LSLGC|Memory}} for more details.


===Run-time error demo scripts===
===Run-time error demo scripts===
Line 31: Line 33:
Compile and run examples like these to experience the script run-time errors.
Compile and run examples like these to experience the script run-time errors.


<pre>
<syntaxhighlight lang="lsl2">default
default
{
{
     state_entry()
     state_entry()
Line 38: Line 39:
         llOwnerSay((string) [llOwnerSay("bye")]); // Script run-time error: Heap Error
         llOwnerSay((string) [llOwnerSay("bye")]); // Script run-time error: Heap Error
     }
     }
}
}</syntaxhighlight>
</pre>


<pre>
<syntaxhighlight lang="lsl2">default
default
{
{
     state_entry()
     state_entry()
Line 49: Line 48:
         list twice = [once, once]; // Script run-time error: Lists may not contain lists
         list twice = [once, once]; // Script run-time error: Lists may not contain lists
     }
     }
}
}</syntaxhighlight>
</pre>


<pre>
<syntaxhighlight lang="lsl2">default
default
{
{
     state_entry()
     state_entry()
Line 62: Line 59:
         llOwnerSay((string) quotient);
         llOwnerSay((string) quotient);
     }
     }
}
}</syntaxhighlight>
</pre>


<pre>
<syntaxhighlight lang="lsl2">default
default
{
{
     state_entry()
     state_entry()
Line 77: Line 72:
         }
         }
     }
     }
}
}</syntaxhighlight>
</pre>


==Compile-time error messages==
==Compile-time error messages==
Line 88: Line 82:
You must name the .x .y .z .s components of a vector or rotation that you're assigning, you can't assign them all at once from a list, for instance:
You must name the .x .y .z .s components of a vector or rotation that you're assigning, you can't assign them all at once from a list, for instance:


<pre>
<syntaxhighlight lang="lsl2">default
default
{
{
     state_entry()
     state_entry()
Line 96: Line 89:
         llOwnerSay((string) vec);
         llOwnerSay((string) vec);
     }
     }
}
}</syntaxhighlight>
</pre>


===ERROR : Byte code assembly failed -- out of memory===
===ERROR : Byte code assembly failed -- out of memory===
Line 104: Line 96:


For example, the compiler says you typed too much script if you cascade too many else-if's:
For example, the compiler says you typed too much script if you cascade too many else-if's:
<pre>
<syntaxhighlight lang="lsl2">demoElseIfCompileError(integer count)
demoElseIfCompileError(integer count)
{
{
     if (count == 0)
     if (count == 0)
Line 127: Line 118:
         ;
         ;
     }
     }
}
}</syntaxhighlight>
</pre>


How much script is too much script can vary astonishingly. For example, the 2007-08 Second Life clients varied as much as 30X, from one to the next. Specifically, the Windows client accepted 22 else-if's and refused 23 else-if's, while Mac OS X was accepting 692 else-if's and refusing 693 else-if's.  
How much script is too much script can vary astonishingly. For example, the 2007-08 Second Life clients varied as much as 30X, from one to the next. Specifically, the Windows client accepted 22 else-if's and refused 23 else-if's, while Mac OS X was accepting 692 else-if's and refusing 693 else-if's. ''On Second Life compilation is now delegated to the server, so these differences have mostly vanished. Standalone test environments and non-LL grids may still compile scripts differently.''


Compilation limits that vary by operating system in effect work as a copy-restriction mechanism. Any resident can run the script compiled by the less limited compiler, but residents who have only the more limited compiler cannot save changes to the source.
Compilation limits that vary by operating system in effect work as a copy-restriction mechanism. Any resident can run the script compiled by the less limited compiler, but residents who have only the more limited compiler cannot save changes to the source.

Latest revision as of 16:43, 4 February 2023

Run-time error messages

A script may stop running, and chat at you the complaint "Script run-time error", followed by another complaint such as:

Script run-time error: Heap Error

Don't speak nonsense. For example, don't return a list of one entry that is the result of a routine that returns no result.

Script run-time error: Lists may not contain lists

Don't try adding a list into a list.

Script run-time error: Math Error

Float divided by zero, integer divided by zero, etc.

See Error/Math for functions that can generate this.

Script run-time error: Stack-Heap Collision

The Stack has collided with the Bytecode or the Heap. (The script has run out of memory)

In LSO each script runs inside 16 KiB of memory divided out among Bytecode, Stack, and Heap.

You can cause collision by compiling too much script, which produces too much Bytecode. The script compiles and saves successfully, but when you rez an object containing the script, the script crashes, immediately or while running.

See llGetFreeMemory and Memory for more details.

Run-time error demo scripts

Compile and run examples like these to experience the script run-time errors.

default
{
    state_entry()
    {
        llOwnerSay((string) [llOwnerSay("bye")]); // Script run-time error: Heap Error
    }
}
default
{
    state_entry()
    {
        list once = [];
        list twice = [once, once]; // Script run-time error: Lists may not contain lists
    }
}
default
{
    state_entry()
    {
        float one = 1.0;
        float zero = 0.0;
        float quotient = one / zero; // Script run-time error: Math Error
        llOwnerSay((string) quotient);
    }
}
default
{
    state_entry()
    {
        list entries = [0];
        while (TRUE)
        {
            entries += entries; // Script run-time error: Stack-Heap Collision
            llOwnerSay((string) llGetListLength(entries));
        }
    }
}

Compile-time error messages

The SL GUI may reject some code that you feel is perfectly clear, printing ERROR at you and then explaining with some further complaint.

ERROR : Type mismatch

You must name the .x .y .z .s components of a vector or rotation that you're assigning, you can't assign them all at once from a list, for instance:

default
{
    state_entry()
    {
        vector vec = (vector) [1, 2, 3]; // ERROR : Type mismatch
        llOwnerSay((string) vec);
    }
}

ERROR : Byte code assembly failed -- out of memory

You must make each script reasonably small.

For example, the compiler says you typed too much script if you cascade too many else-if's:

demoElseIfCompileError(integer count)
{
    if (count == 0)
    {
        ;
    }
    else if (count == 1)
    {
        ;
    }
    else if (count == 2)
    {
        ;
    }
    ...
    ... // ERROR : Byte code assembly failed -- out of memory
    ... // or ERROR : Syntax error
    ...
    else if (count == ...)
    {
        ;
    }
}

How much script is too much script can vary astonishingly. For example, the 2007-08 Second Life clients varied as much as 30X, from one to the next. Specifically, the Windows client accepted 22 else-if's and refused 23 else-if's, while Mac OS X was accepting 692 else-if's and refusing 693 else-if's. On Second Life compilation is now delegated to the server, so these differences have mostly vanished. Standalone test environments and non-LL grids may still compile scripts differently.

Compilation limits that vary by operating system in effect work as a copy-restriction mechanism. Any resident can run the script compiled by the less limited compiler, but residents who have only the more limited compiler cannot save changes to the source.

See llGetFreeMemory, llMessageLinked.

ERROR : Syntax error

You must punctuate the script and spell the words of the script as will please the compiler, of course.

Also you must make each script reasonably small. The compiler may astonishingly complain of a "syntax" error rather than politely complaining more specifically of an "out of memory" "byte code assembly failed" error, when you make a script unreasonably large.

For example, the 2007-08 Windows Second Life client complained of a Syntax error if you cascaded too many else-if's. The exact limits enforced can vary astonishingly. For example, the 2007-08 Windows Second Life client sometimes accepted as many as 22 cascaded else-if's, but also sometimes rejected as few as 19 cascaded else-if's, depending on other details of the script.

Programmers who learned LSL on one compiler may feel that that compiler's limits are reasonable, e.g., up to five hundred cascaded else-if's in Mac OS X, while programmers trained on another compiler may feel instead that only its significantly different limits are reasonable, e.g., no more than a dozen cascaded else-if's in Windows.