[Tutorial] Fixes for runtime errors
#1

Fixes for runtime errors

Sections
  • Runtime error 3: Stack/heap collision (insufficient stack size)
  • Runtime error 4: Array index out of bounds
  • Runtime error 5: Invalid memory access
  • Runtime error 7: Stack underflow
  • Runtime error 10: Native function failed
  • Runtime error 11: Divide by zero
  • Runtime error 12: (sleep mode)
  • Runtime error 16: Out of memory
  • Runtime error 17: Invalid/unsupported P-code file format
  • Runtime error 19: File or function is not found
  • Runtime error 20: Invalid index parameter (bad entry point)
  • Runtime error 22: AMX not initialized (or doubly initialized)
Introduction
New scripters are always having issues with certain runtime problems, so this tutorial will help suppress of those errors to ensure a safe, stable mode.

Basically, runtime errors are errors that are generated at runtime and not by your compiler. I've listed all of the common ones below (there are either some missing, or so rare that nobody ever receives them) to the best of my knowledge, so read on if you're interested.

Runtime error 3
Your script has apparently ran out of local memory. The stack is where any local variables are allocated and stored, in terms of memory. This means that the stack and the heap are colliding with each other, which could effectively corrupt data in the long run.

Solution: Try to use less cells for local declaration. For example, huge strings can be declared using "static" so it isn't allocated every function call. Alternatively, there's "#pragma dynamic x" but that's only if you're lazy.

Runtime error 4
Very simple, you're trying to access out-of-bound data in an array, in other words, a cell inside of an array that doesn't exist.

Solution: If you're using the crashdetect plugin, it'll tell you which callback the error is in. Simply debug your code until you find the culprit, then remove it.

Runtime error 5
You are either trying to incorrectly access memory, or the system was unable to read or write any memory because of an incorrectly used native.

Solution: Look in the callback and see if you can find the problem. These are really tricky to find, so you have to be careful and debug your code one-by-one.

Runtime error 7
This is caused by removing too much data from the stack. Eventually, the stack register becomes a negative number and corrupts all of your shit.

Solution: Debug the code and remove any code that uses #emit until the problem is found.

Runtime error 10
A native function has been used incorrectly, or one of the parameters are incorrectly used.

Solution: Remove the corresponding native from your code and look up a way to correctly use that function.

Runtime error 11
This is caused by dividing zero with another number.

Solution: Don't divide by zero, idiot!

Runtime error 12
This is caused by using "sleep mode" in a function other than the entry point (main). This is a very rare issue, and it can sometimes be caused by external libraries.

Solution: Only use "sleep" in the main entry.

Runtime error 16
Your computer has ran out of memory, and there's no way to store the data any further.

Solution: Get a new computer, or use less memory (pointing back to error 3).

Runtime error 17
Your .AMX file is corrupt and contains an invalid P-code format. This can be caused by trying to run the server while the script is compiling.

Solution: Shut the server off and compile the script again. If you've uploaded the .amx file, then upload it again.

Runtime error 19
One of the most common known problems in SA-MP. This simply means that the include and plugin versions might not match. One of them is either outdated, or newer than the other.

Solution: Update your plugins and includes. If you can, disable your plugins until the problem is found.

Runtime error 20
When running a gamemode, the "main" function indicates the entry point for that mode. Without it, your mode won't function properly.

Solution: Add this snippet under your includes:

pawn Код:
main() {}
Runtime error 22
This is caused by the abstract machine not being initialized properly, or being initialized twice.

Solution: Find out where the problem is coming from. Disable any filterscripts or plugins, and debug your mode. This error also pops up frequently when using #emit incorrectly.


Notes
  • I apologize for any incorrect information. It was late when I made this tutorial, you know.
  • There are more runtime problems (I believe there's around ~25) but I only listed the frequent ones.
  • Whoever stole the pancake mix that was in my drawer, you better fucking give it back, NOW.
Conclusion
Okay, so you've managed to reach the end of this tutorial, good for you.

Alternatively, you can also solve these problems yourself by using common sense, debugging your code and running the usual tests.
Reply


Messages In This Thread
Fixes for runtime errors - by Emmet_ - 21.12.2013, 04:21
Re: Fixes for runtime errors - by qazwsx - 21.12.2013, 04:45
Re: Fixes for runtime errors - by TahaAsif12 - 21.12.2013, 05:45
Re: Fixes for runtime errors - by KingServerIRAN - 21.12.2013, 08:59
Re: Fixes for runtime errors - by gtakillerIV - 21.12.2013, 09:09
Re: Fixes for runtime errors - by BizzyD - 21.12.2013, 10:42
Re: Fixes for runtime errors - by iZN - 21.12.2013, 17:51
Re: Fixes for runtime errors - by DJ_Shocker - 22.12.2013, 04:24
Re: Fixes for runtime errors - by Emmet_ - 22.12.2013, 04:46
Re: Fixes for runtime errors - by Lordzy - 23.12.2013, 06:19

Forum Jump:


Users browsing this thread: 1 Guest(s)