Stack corrupted! Heap underflow
#1

Hy community,

I need your help/advice. I loaded crashdetect plugin to track down some errors in my script and somehow got into this problem:

pawn Code:
[13:05:08] Script[gamemodes/newegDB.amx]: In file 'I:\_eGaming\samp\_new_mysql-0.3d\__CORECTAT0.3c\pawno-3\include\float.inc' at line 108:
[13:05:08] Script[gamemodes/newegDB.amx]: Run time error 8: "Heap underflow"
[13:05:08] Error information:
[13:05:08]   Heap index (HEA) is 0x8B, heap bottom (HLW) is 0x3F20FC
[13:05:08] Call stack (most recent call first):
[13:05:08]   Stack corrupted!
The file float.inc is the standard file from samp(pawn) package.
the line 108 is:
pawn Code:
stock Float:operator-(Float:oper)
    return oper^Float:cellmin;                  /* IEEE values are sign/magnitude */
The problem appears on something very basic like:
pawn Code:
GetPlayerHealth(playerid, health);
SetPlayerHealth(playerid, health - 2.0);
if I modify the script into:

pawn Code:
GetPlayerHealth(playerid, health);
SetPlayerHealth(playerid, floatsub(health, 2.0));
The problem vanished.

Does anyone have any idea why this thing happens ?
Should I use Floatadd, Floatsub, Floatmul, Floatdiv functions instead of standard operators +,-,*,/ ?

My compile output is:
pawn Code:
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase

Header size:          21152 bytes
Code size:          1581964 bytes
Data size:          4137212 bytes
Stack/heap size:      16384 bytes; estimated max. usage=1253 cells (5012 bytes)
Total requirements: 5756712 bytes

Done.
================ READY ================
Thank you in advance,
Mike
Reply
#2

Quote:
Originally Posted by xxmitsu
View Post
My compile output is:
pawn Code:
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase

Header size:          21152 bytes
Code size:          1581964 bytes
Data size:          4137212 bytes
Stack/heap size:      16384 bytes; estimated max. usage=1253 cells (5012 bytes)
Total requirements: 5756712 bytes

Done.
================ READY ================
This, and only this is your problem. Let me quote ****** here:
Quote:

This means that the compiler has detected that you are using more stack/heap space than is available. A lot of important information is stored on the stack, such as who called the current function, so PAWN knows where to return to. If you use too much memory, because of the way information is allocated, you can overwrite the stack information, returning to a random point in code and almost certainly crashing. At the very least you will get corrupted data where it's been overwritten by other data. When people get this message the standard advice is to use "#pragma dynamic", which is a workaround, not a fix - I find it very odd that something the size of YSI can not generate this error but people's tiny scripts can, don't you?

https://sampforum.blast.hk/showthread.php?tid=55261
I suggest you read the whole topic and optimize your code where needed.
Reply
#3

Yes, I'm using '-v' compile flag. My compile parameters are:
Code:
"I:\_eGaming\samp\_new_mysql-0.3d\__CORECTAT0.3c\pawno-3\pawncc.exe" "$(FILE_NAME)" -; -\ -( -d0 -O1 -v2 -r
Seems it's ok now, I've changed anywhere where I had like

Code:
if(health > 20.0)..
SetPlayerPos(pldi, coordx+2.0,..
new Float:a;
a = 20.1 + 2.0;
....etc.
Into int.
Code:
if(health > 20)..
SetPlayerPos(pldi, coordx+2,..
new Float:a;
a = 20 + 2;
....etc.
Thank you for help!
+rep
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)