SA-MP Forums Archive
Run time error 7: "Stack underflow" - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Run time error 7: "Stack underflow" (/showthread.php?tid=298511)



Run time error 7: "Stack underflow" - TheLazySloth - 21.11.2011

Okay, I'm getting this error that is preventing my gamemode from fully starting.

Run time error 7: "Stack underflow"

I don't know what it is, or what I did to get this error, so I debugged the gamemode and it seems to crash after my...
LoadServer();
... function.

Here's the code to that, please help me.

pawn Code:
stock LoadServer()
{
    new
        Query[128],
        Data;
    format(Query, 128, "SELECT * FROM serverdata WHERE Enabled = 1");
    mysql_query(Query);
    mysql_store_result();
    Data = mysql_num_rows();
    mysql_free_result();
   
    if(Data >= 1)
    {
        mysql_query(Query);
        mysql_store_result();
        while(mysql_fetch_row_format(Query, "|"))
        {
            new
                Enabled[128],
                Value[128];
               
            mysql_fetch_field_row(Enabled, "Enabled");
/*          #pragma unused Enabled
Calgon suggested removing this but it did not fix the error. */

               
            mysql_fetch_field_row(Server[sName], "Name");
           
            mysql_fetch_field_row(Server[sVersion], "Version");
           
            mysql_fetch_field_row(Server[sMap], "Map");
           
            mysql_fetch_field_row(Server[sWebsite], "Website");
           
            mysql_fetch_field_row(Server[sTime], "Time");
           
            mysql_fetch_field_row(Value, "Hour");
            Server[sHour] = strval(Value);
           
            mysql_fetch_field_row(Value, "Minute");
            Server[sMinute] = strval(Value);
           
            mysql_fetch_field_row(Value, "Second");
            Server[sSecond] = strval(Value);
           
            mysql_fetch_field_row(Server[sDate], "Date");
           
            mysql_fetch_field_row(Value, "Year");
            Server[sYear] = strval(Value);
           
            mysql_fetch_field_row(Value, "Month");
            Server[sMonth] = strval(Value);
           
            mysql_fetch_field_row(Server[sMonthName], "MonthName");
           
            mysql_fetch_field_row(Value, "Day");
            Server[sDay] = strval(Value);
           
            mysql_fetch_field_row(Value, "Weather");
            Server[sWeather] = strval(Value);
           
            mysql_fetch_field_row(Server[sOwner], "Owner");
           
            mysql_fetch_field_row(Server[sCoOwner], "CoOwner");
           
            mysql_fetch_field_row(Server[sScripter], "Scripter");
           
            mysql_fetch_field_row(Server[sMapper], "Mapper");
        }
        mysql_free_result();
    }
    return 1;
}
I am using BlueG's version of MySQL.

Update:
Debug.txt :
Code:
[21:30:08] >> mysql_query( Connection handle: 1 )

[21:30:08] CMySQLHandler::Query(SELECT * FROM serverdata WHERE Enabled = 1) - Successfully executed.

[21:30:08] >> mysql_store_result( Connection handle: 1 )

[21:30:08] CMySQLHandler::StoreResult() - Result was stored.

[21:30:08] >> mysql_fetch_row_format( Connection handle: 1 )

[21:30:08] CMySQLHandler::FetchRow() - Return: 1|TheLazySloth's Server|0.3c R5|Red County|forum.sa-mp.com|20:03:34|20|3|34|11/20/2011|2011|11|November|20|2|TheLazySloth|Unknown|TheLazySloth|TheLazySloth

[21:30:08] >> mysql_fetch_field_row( Connection handle: 1 )

[21:30:08] CMySQLHandler::FetchField("Enabled") - 1

[21:30:08] >> mysql_fetch_field_row( Connection handle: 1 )

[21:30:08] CMySQLHandler::FetchField("Name") - TheLazySloth's Server

[21:30:08] >> mysql_fetch_field_row( Connection handle: 1 )

[21:30:08] CMySQLHandler::FetchField("Version") - 0.3c R5

[21:30:08] >> mysql_fetch_field_row( Connection handle: 1 )

[21:30:08] CMySQLHandler::FetchField("Map") - Red County

[21:30:08] >> mysql_fetch_field_row( Connection handle: 1 )

[21:30:08] CMySQLHandler::FetchField("Website") - forum.sa-mp.com

[21:30:08] >> mysql_fetch_field_row( Connection handle: 1 )

[21:30:08] CMySQLHandler::FetchField("Time") - 20:03:34

[21:30:08] >> mysql_fetch_field_row( Connection handle: 1 )

[21:30:08] CMySQLHandler::FetchField("Hour") - 20

[21:30:08] >> mysql_fetch_field_row( Connection handle: 1 )

[21:30:08] CMySQLHandler::FetchField("Minute") - 3

[21:30:08] >> mysql_fetch_field_row( Connection handle: 1 )

[21:30:08] CMySQLHandler::FetchField("Second") - 34

[21:30:08] >> mysql_fetch_field_row( Connection handle: 1 )

[21:30:08] CMySQLHandler::FetchField("Date") - 11/20/2011

[21:30:08] >> mysql_fetch_field_row( Connection handle: 1 )

[21:30:08] CMySQLHandler::FetchField("Year") - 2011

[21:30:08] >> mysql_fetch_field_row( Connection handle: 1 )

[21:30:08] CMySQLHandler::FetchField("Month") - 11

[21:30:08] >> mysql_fetch_field_row( Connection handle: 1 )

[21:30:08] CMySQLHandler::FetchField("MonthName") - November

[21:30:08] >> mysql_fetch_field_row( Connection handle: 1 )

[21:30:08] CMySQLHandler::FetchField("Day") - 20

[21:30:08] >> mysql_fetch_field_row( Connection handle: 1 )

[21:30:08] CMySQLHandler::FetchField("Weather") - 2

[21:30:08] >> mysql_fetch_field_row( Connection handle: 1 )

[21:30:08] CMySQLHandler::FetchField("Owner") - TheLazySloth

[21:30:08] >> mysql_fetch_field_row( Connection handle: 1 )

[21:30:08] CMySQLHandler::FetchField("CoOwner") - Unknown

[21:30:08] >> mysql_fetch_field_row( Connection handle: 1 )

[21:30:08] CMySQLHandler::FetchField("Scripter") - TheLazySloth

[21:30:08] >> mysql_fetch_field_row( Connection handle: 1 )

[21:30:08] CMySQLHandler::FetchField("Mapper") - TheLazySloth

[21:30:08] >> mysql_fetch_row_format( Connection handle: 1 )

[21:30:08] >> mysql_free_result( Connection handle: 1 )

[21:30:08] CMySQLHandler::FreeResult() - Result was successfully free'd.
Update #2: I made LoadServer() return print("Debug."); and when I turn the server on again, still gives me the error but it displays Debug. on the server console... What is up?

Update #3: I don't get the error anymore, but I get the same problem, the server fails to load fully and when I debug it stops at the Loadserver(); function.


Re: Run time error 7: "Stack underflow" - Calgon - 21.11.2011

Remove:
Code:
#pragma unused Enabled
...and see what happens.


Re: Run time error 7: "Stack underflow" - TheLazySloth - 21.11.2011

I still get the error =[

Thanks for your suggestion, much appreciated =]

Update: Added Debug.txt to info, meybe it'll help you guys help me.

Update #2: I made LoadServer() return print("Debug."); and when I turn the server on again, still gives me the error but it displays Debug. on the server console... What is up?

Update #3: I don't get the error anymore, but I get the same problem, the server fails to load fully.


Re: Run time error 7: "Stack underflow" - TheLazySloth - 21.11.2011

Do you get any warnings or other messages when you compile (I'm thinking specifically verbose output after the "compilation complete" message).
Nope.

Stack and heap problems are generally caused by calling too many functions with lots of local variables inside each other - PAWN just runs out of memory to store them.
Oh I know what you are talking about like when you have strings reaching 2000, all I have is MySQL Connect, Server Stats (Name, Version, Map, Website, Time, Date ...), Server Saving, and Server Loading.

String sizes are fair (I literally counted the sizes for max highest, 877 on MySQL Saving), only two custom callbacks SaveServer(); LoadServer();

So this error is very strange.


Re: Run time error 7: "Stack underflow" - TheLazySloth - 21.11.2011

Yes, the load function return 1; works but the code after LoadServer(); in OnGameModeInit under is not working. So it has to be the LoadServer(); function.

I take LoadServer(); out of OnGameModeInit and the server runs fine, but this function is required to get my server's info from the database so if you can think of a solution, by all means anything...

Thank you for spending your time helping me =]


Re: Run time error 7: "Stack underflow" - TheLazySloth - 21.11.2011

I was just about to just re-write it, cause before, it worked... last night, it was working perfectly... but now its... meh' pissing me off kinda.

I'll come back with the results.

Edit:
Also, run which Query twice?
format(Query, 128, "SELECT * FROM serverdata WHERE Enabled = 1");
Is ran three times, actually once.

1. To check if there's data in the Database.
2.A. If there's no data it is not ran the 2nd or 3rd time and the script moves on.
2.B. If there's data it's ran again, to get the Primary Key that is Enabled.
3. If there's data and the 2nd Query grabbed the Primary Key then this is called to start sending the data to MySQL and store them in the Server variable.

Like I said, I did no changes to the script since last night except try to find the problem by adding alot of print("Debug."); after every other line to see where it stops and it worked perfectly last night.


Re: Run time error 7: "Stack underflow" - TopSecret - 21.11.2011

It's probably due to a buffer overflow (e.g. mysql_fetch_field_row overwrites the number of arguments stored on the stack so the AMX pops too much cells), the MySQL plugin doesn't check output string size in either of its natives (this is clearly a bug). You might try increasing your output strings so the data will fit them.


Re: Run time error 7: "Stack underflow" - TheLazySloth - 21.11.2011

^^^ Changed them to 1024 string sizes (SA-MP Max by default) and it worked... but won't this cause server deficiencies?


Re: Run time error 7: "Stack underflow" - TheLazySloth - 21.11.2011

VARCHAR is always =]

Quote:

mysql_query("CREATE TABLE IF NOT EXISTS serverdata \
(\
Enabled int NOT NULL DEFAULT '1', \
Name varchar(128), \
Version varchar(128), \
Map varchar(128), \
Website varchar(128), \
Time varchar(128), \
Hour int, \
Minute int, \
Second int, \
Date varchar(128), \
Year int, \
Month int, \
MonthName varchar(128), \
Day int, \
Weather int, \
Owner varchar(128), \
CoOwner varchar(128), \
Scripter varchar(128), \
Mapper varchar(128), \
PRIMARY KEY (Enabled)\
)");

=] Thank you all =]


Re: Run time error 7: "Stack underflow" - TheLazySloth - 21.11.2011

[HiC]TheKiller's MySQL Tut says to do it like that, I'm only following directions.

https://sampforum.blast.hk/showthread.php?tid=159785

This is all different from PHP except the SQL Syntaxs... =/
At least those are the same.