Runtime errors

This page covers runtime errors logged by the AMX interpreter, and reasons why HLDS may crash, exit, or stop responding.

AMX runtime errors

As the name suggests, these errors appear in your server log file / server console window when your AMX plugin encounters an error whilst running. The AMX engine defines the following runtime errors, although only a few of them are common in Admin Mod plugins:

3 - AMX_ERR_STACKERR
This means that the plugin has run out of memory for local variables. By default each plugin gets 8K for local variables. See this guide for techniques on how to deal with this error message.
4 - AMX_ERR_BOUNDS
This means you are referring to an element outside the bounds of an array - e.g. The following will generate this error:
new arr[10];
for (i=0;i<20;i++) {
  arr[i] = 1;
}
10 - AMX_ERR_NATIVE
This means an error has occurred inside a native function provided by Admin Mod. Usually this is because you have passed it invalid values in its arguments. There is one known way to generate this error when your arguments are valid; call the readfile() function and attempt to read a line that is too long for the buffer you are providing to receive it.
11 - AMX_ERR_DIVIDE
You have attempted to divide a number by zero. Don't be doing this sort of thing - it's not big and it's not clever.
17 - AMX_ERR_FORMAT
Invalid file format. You can cause this by putting the sma file in you plugin.ini instead of the AMX file, but your not that much of a noob are you? You can also cause it by using a partially compiled, or a zero-byte AMX file after a compiler error.
19 - AMX_ERR_NOTFOUND
Function not found. This can occur when your plugin fails in plugin_init with some other error, but registered a command handler, created a timer or started a vote before it failed. This error will occur when Admin Mod attempts to call the timer handler, vote handler or command handler function.
22 - AMX_ERR_INIT
This means an internal AMX error has occurred. The only known way of causing this is due to a bug in the compiler regarding using the ++ or -- with array elements. The following code will cause this error:
new arr[10];
arr[1]++;
The workaround is not to use ++/-- with array elements:
new arr[10];
arr[1]=arr[1]+1;

The other less common error messages are:

1 - AMX_ERR_EXIT
This means the exit statement was used in a plugin. Don't, always use return in an Admin Mod plugin.
2 - AMX_ERR_ASSERT
This means the plugin contained an assert statement and the assertion has failed. Check what was being asserted and either fix the code or change the assertion condition.
5 - AMX_ERR_MEMACCESS
Invalid memory access. No idea how to cause it.
6 - AMX_ERR_INVINSTR
Invalid instruction. No idea how to cause it.
7 - AMX_ERR_STACKLOW
Stack underflow. No idea how to cause it.
8 - AMX_ERR_HEAPLOW
Heap underflow. No idea how to cause it.
9 - AMX_ERR_CALLBACK
No callback, or invalid callback. No idea how to cause it.
12 - AMX_ERR_SLEEP
Gone into sleep mode - code can be restarted. No idea how to cause it.
16 - AMX_ERR_MEMORY
Out of memory. I presume this means the AMX engine couldn't get memory from the OS. Memory problems caused by allocating stack variables within the plugin result in error 3, not this error.
18 - AMX_ERR_VERSION
File is for a newer version of the AMX. Unless you have a newer version of the Small compiler than the one that came with Admin Mod, this shouldn't happen.
20 - AMX_ERR_INDEX
Invalid index parameter (bad entry point). This would point to a bug in the compiler to do with the table of public functions that it builds. It is not related to array indexes.
21 - AMX_ERR_DEBUG
Debugger cannot run. Debugger? What debugger?
23 AMX_ERR_USERDATA
Unable to set user data field (table full). Pass. Sounds like it might be something to do with a plugin getting too big - e.g. too many lines / variables / functions.
24 AMX_ERR_INIT_JIT
Cannot initialise the JIT. Shouldn't happen - Admin Mod doesn't use Small's JIT feature.
25 AMX_ERR_PARAMS
Parameter error. No idea how to cause it.

If you encounter one of the errors not explained here, post to the Scripting Forum for help. Post even if you solve the problem so we can update this documentation.

Half-life crashes

There are innumerable ways to cause this, but here are a few:

Forgetting to prototype functions
If you don't prototype all your functions (e.g. declare them before use with the forward keyword), the Small compiler can on occasions occasionally forget to include some of them in the compiled AMX file, but doesn't produce any compiler error messages. You should always prototype all functions to prevent this.
Infinite loops
If your code goes into an infinite loop, it will hang the game. The hlds process will not crash, it will simply hang.
Using new within a for loop declaration
If you use the new statement inside a for loop declaration, the Small compiler does not always remove the variable you are declaring from the stack properly, resulting in stack corruption and random AMX errors or HLDS crashes depending on what was on the stack at the time. One definite way to cause this problem is to use the break statement inside the loop - e.g. The following will crash Half-life:
func() {
  for(new i=1;i<10;i++) {
    break;
  }
}
Moving the new statement outside the loop makes it run correctly:
func() {
  new i;
  for(i=1;i<10;i++) {
    break;
  }
}