SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 21/12/2013, 04:21 AM   #1
Emmet_
Guest
 
Posts: n/a
Default Fixes for runtime errors

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 Code:
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 With Quote
Old 21/12/2013, 04:45 AM   #2
qazwsx
Huge Clucker
 
qazwsx's Avatar
 
Join Date: Jun 2013
Location: Semarang,Indonesia
Posts: 415
Reputation: 55
Default Re: Fixes for runtime errors

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
__________________
Ive left SAMP Scripting. I wont keep the update of my gamemodes. I might come back someday later, but didnt think about to come back to scripting ATM. However, I'd always come around to forums, chcking stuffs happened, and responds to thoose who have give their feedback on my gamemode.

-Regard
qazwsx
qazwsx is offline   Reply With Quote
Old 21/12/2013, 05:45 AM   #3
TahaAsif12
Huge Clucker
 
Join Date: Nov 2013
Posts: 271
Reputation: 23
Default Re: Fixes for runtime errors

Excellent tutorial! keep it up dude!
I was getting runtime error 17 but after reading your explaination, it got fixed!
__________________
TahaAsif12 is offline   Reply With Quote
Old 21/12/2013, 08:59 AM   #4
KingServerIRAN
Banned
 
Join Date: Aug 2013
Location: SarBNR, IRAN!. Reputation:9999. . Posts2: 160754
Posts: 365
Reputation: 45
Default Re: Fixes for runtime errors

I Likeeeeeeeee This tutorial
KingServerIRAN is offline   Reply With Quote
Old 21/12/2013, 09:09 AM   #5
gtakillerIV
High-roller
 
gtakillerIV's Avatar
 
Join Date: Sep 2011
Location: UAE, Sharjah.
Posts: 1,002
Reputation: 201
Default Re: Fixes for runtime errors

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.

Last edited by gtakillerIV; 21/12/2013 at 10:50 AM. Reason: Added some more detail.
gtakillerIV is offline   Reply With Quote
Old 21/12/2013, 10:42 AM   #6
BizzyD
Gangsta
 
BizzyD's Avatar
 
Join Date: Jan 2011
Location: Home
Posts: 938
Reputation: 66
Default Re: Fixes for runtime errors

Nice tutorial, and yeah. As the guy above me said.
__________________
We never fail, we only shine with brilliance. One king one faith one religion. And if you hear me come and join the revolution
BizzyD is offline   Reply With Quote
Old 21/12/2013, 05:51 PM   #7
iZN
High-roller
 
Join Date: Jun 2010
Posts: 2,448
Reputation: 569
Default Re: Fixes for runtime errors

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.
__________________
iZN is offline   Reply With Quote
Old 22/12/2013, 04:24 AM   #8
DJ_Shocker
Huge Clucker
 
Join Date: Jul 2012
Posts: 420
Reputation: 42
Default Re: Fixes for runtime errors

Quote:
Originally Posted by Emmet_ View Post
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
__________________
DJ_Shocker is offline   Reply With Quote
Old 22/12/2013, 04:46 AM   #9
Emmet_
Guest
 
Posts: n/a
Default Re: Fixes for runtime errors

Thanks, everyone!

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

Quote:
Originally Posted by DJ_Shocker View Post
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 With Quote
Old 23/12/2013, 06:19 AM   #10
Lordzy
High-roller
 
Join Date: Mar 2012
Location: NetherRealm
Posts: 2,763
Reputation: 1175
Default Re: Fixes for runtime errors

This is really useful, thanks for it Emmet! Oh and by the way :
Quote:
Originally Posted by Emmet_ View Post
  • Whoever stole the pancake mix that was in my drawer, you better fucking give it back, NOW.
__________________
Currently inactive - I don't play at any SA-MP servers nor work on anything in PAWN for now. The projects that I've done so far in PAWN, which requires updates will be taking some time.
Lordzy is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Runtime errors and converting server to 0.3x? Josh_Main Scripting Help 6 13/06/2013 01:04 PM
Help Needed With Runtime Errors Joshy_Elite Scripting Help 1 02/09/2012 09:39 AM
Fixes to All Errors [COD5]Zero Scripting Help 5 19/06/2012 12:09 AM
#include <datagram> not supported? Runtime errors! Pred2k3 Help Archive 3 23/07/2009 09:26 AM


All times are GMT. The time now is 02:38 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.