[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
#2

Very great tutorial!
Well done, emmet_

I myself got helped by your tutorial, since ive never seen tutorial which discuss thing like this.
Could be usefull for newbie, or someone who just getting started.

+REP
Reply
#3

Excellent tutorial! keep it up dude!
I was getting runtime error 17 but after reading your explaination, it got fixed!
Reply
#4

I Likeeeeeeeee This tutorial
Reply
#5

Looking good. Though I hate the fact that I gotta scroll up just to see what runtime error 22 is for example.

You could make it like:

Run time error 22: AMX not initialized (or doubly initialized)

To elaborate abit more on run time error 19: It means that the function you're trying to use in your game mode might've been abandoned in the latest version of the include/plugin or you're using an older version that doesn't support/have that function.

For example. The creator of the plugin deleted a function(or even changed the name of it) that was in an older version and released a new version. You took only the include and forgot about the .dll or .so. After that you used one of the new functions inside of your gamemode that the creator added. Then you clicked on compile and the compiler compiled the script. You then started the server and it starts complaining about you using a function that is not included inside the .dll or .so ( File or function is not found ). This can also be the other way round. Only downloading the new .dll or .so and forgetting the include file. In that case, the script won't even compile at all. Instead, it'll give out an error saying something like "Symbol undefined".

That's why it's very important to update both the include and the .dll or .so.

If I've made a mistake in my post, please tell me.
Reply
#6

Nice tutorial, and yeah. As the guy above me said.
Reply
#7

This actually increased my knowledge because I actually don't know about other run time errors, to be honest I never had any run time error; it was a great problem for me when I was an beginner scripter. Good work.
Reply
#8

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
Fixes for runtime errors

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

Solution: Don't divide by zero, idiot!
Am i the only one that LOLd at this?

Well done Emmet! +Rep
Reply
#9

Thanks, everyone!

@gtakillerIV: Good idea, it'll be added soon! Thanks.

Quote:
Originally Posted by DJ_Shocker
Посмотреть сообщение
Am i the only one that LOLd at this?

Well done Emmet! +Rep
Haha, I laughed a bit when I made it.

It's not meant to be offensive, though. I just thought that I'd add a joke in it for the amusement!
Reply
#10

This is really useful, thanks for it Emmet! Oh and by the way :
Quote:
Originally Posted by Emmet_
Посмотреть сообщение
  • Whoever stole the pancake mix that was in my drawer, you better fucking give it back, NOW.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)