Infinite loop that freezes the server -
AliveBG - 22.05.2015
Hello,
I have a problem with infinite loops. Where do you think is the cause of infinite loop here:
PHP код:
public SpeedoUpdate()
{
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
{
if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))
{
new Float:x, Float:y, Float:z, Float:hp, string[24], vehicleid = GetPlayerVehicleID(i);
if(Speedo[i] == 0)
{
TextDrawShowForPlayer(i, vspeed[i]);
if(GetVehicleModel(vehicleid) != 509 && GetVehicleModel(vehicleid) != 481 && GetVehicleModel(vehicleid) != 510)
{
TextDrawShowForPlayer(i, vhealth[i]);
}
}
GetVehicleVelocity(vehicleid, x, y, z);
GetVehicleHealth(vehicleid, hp);
if(Kmhmph[i] == 0)
{
format(string, sizeof(string), "Speed: %dkm/h", floatround(floatsqroot(((x*x)+(y*y))+(z*z))*180.666667));
TextDrawSetString(vspeed[i], string);
TextDrawBackgroundColor(vspeed[i], 369098796);
TextDrawFont(vspeed[i], 2);
TextDrawLetterSize(vspeed[i], 0.349999, 1.299996);
TextDrawColor(vspeed[i], 0xC3C3C3FF);
TextDrawSetOutline(vspeed[i], 1);
TextDrawSetProportional(vspeed[i], 1);
}
if(Kmhmph[i] == 1)
{
format(string, sizeof(string), "Speed: %dm/s", floatround(floatsqroot(((x*x)+(y*y))+(z*z))*86.666667));
TextDrawSetString(vspeed[i], string);
TextDrawBackgroundColor(vspeed[i], 369098796);
TextDrawFont(vspeed[i], 2);
TextDrawLetterSize(vspeed[i], 0.349999, 1.299996);
TextDrawColor(vspeed[i], 0xC3C3C3FF);
TextDrawSetOutline(vspeed[i], 1);
TextDrawSetProportional(vspeed[i], 1);
}
format(string, sizeof(string), "Health: %d", floatround(hp));
TextDrawSetString(vhealth[i], string);
TextDrawBackgroundColor(vhealth[i], 369098796);
TextDrawFont(vhealth[i], 2);
TextDrawLetterSize(vhealth[i], 0.349999, 1.299996);
TextDrawColor(vhealth[i], 0xC3C3C3FF);
TextDrawSetOutline(vhealth[i], 1);
TextDrawSetProportional(vhealth[i], 1);
if(Speedo[i] == 1)
{
TextDrawHideForPlayer(i, vspeed[i]);
TextDrawHideForPlayer(i, vhealth[i]);
}
}
if(!IsPlayerInAnyVehicle(i))
{
TextDrawHideForPlayer(i, vspeed[i]);
TextDrawHideForPlayer(i, vhealth[i]);
}
}
}
and
PHP код:
public Production()
{
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
{
if(IsPlayerConnected(i))
{
if(pusedrug[i] == 1) {
SetPlayerArmedWeapon(i, 9);
SetPlayerWeather(i, 19); }
if(pusedrug[i] == 2) {
SetPlayerArmedWeapon(i, 9);
SetPlayerWeather(i, -74); }
if(pusedrug[i] == 3) {
SetPlayerArmedWeapon(i, 9);
SetPlayerWeather(i, 9); }
if(pusedrug[i] == 4) {
SetPlayerArmedWeapon(i, 9);
SetPlayerWeather(i, -130); }
}
}
}
Re: Infinite loop that freezes the server -
Konstantinos - 22.05.2015
There isn't any infinite loop on those. You better look for
while loops.
Re: Infinite loop that freezes the server -
AliveBG - 22.05.2015
Hmm,
PHP код:
[12:56:11] [debug] AMX backtrace:
[12:56:11] [debug] #0 native PrintAmxBacktrace () from crashdetect.dll
[12:56:11] [debug] #1 001af998 in public Production () at D:\sed v3\gamemodes\sedbg.pwn:25233
[12:56:11] [debug] AMX backtrace:
[12:56:11] [debug] #0 native PrintAmxBacktrace () from crashdetect.dll
[12:56:11] [debug] #1 001af998 in public Production () at D:\sed v3\gamemodes\sedbg.pwn:25233
[12:56:11] [debug] AMX backtrace:
[12:56:11] [debug] #0 native PrintAmxBacktrace () from crashdetect.dll
[12:56:11] [debug] #1 001b0e84 in public SpeedoUpdate () at D:\sed v3\gamemodes\sedbg.pwn:25332
or either
PHP код:
public GodCarFix()
{
for___loop(new i = 0; i < MAX_VEHICLES; i++)
{
if(IsGodCar[i] == 1)
{
SetVehicleHealth(i, 1000);
}
}
return 1;
}
Re: Infinite loop that freezes the server -
Konstantinos - 22.05.2015
It says PrintAmxBacktrace function from crashdetect is the cause, the public functions are in which this function was called. If you haven't used the function to your script, it's the first time I see such a problem.
What's the line 25233 and 25332?
Also "for___loop"? Have you define it as "for"? If not, post how.
Re: Infinite loop that freezes the server -
AliveBG - 22.05.2015
Yea, I did define at the top of the script:
PHP код:
#include <crashdetect>
#define for___loop(%1;%2;%3) \
PrintAmxBacktrace(); \
for(%1;%2;%3)
#define while___loop(%1) \
PrintAmxBacktrace(); \
while(%1)
25233 line:
PHP код:
for___loop(new i = 0, j = GetPlayerPoolSize(); i <= j; i++) // From Production()
25332:
PHP код:
for___loop(new i = 0, j = GetPlayerPoolSize(); i <= j; i++) // From SpeedoUpdate()
Re: Infinite loop that freezes the server -
Konstantinos - 22.05.2015
I know you tried to print details with crashdetect's help but by using GetPlayerPoolSize, you know the max value and the operators are correct so there isn't any chance for an infinite loop there.
Remove the definitions and replace it to:
pawn Код:
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
use the old good debugging method with prints calls inside each public function. By that, you'll find out in what callback stopped so you can debug it in there as well (the functions you call inside the callback and in the callback itself).
Re: Infinite loop that freezes the server -
RaeF - 22.05.2015
Where you call onspedoupddate?
Re: Infinite loop that freezes the server -
AliveBG - 22.05.2015
OnGameModeInit:
productiontimer = SetTimer("Production", 100, 1);
speedotimer = SetTimer("SpeedoUpdate", 100, 1);
Re: Infinite loop that freezes the server -
RaeF - 22.05.2015
Try to change it to 500 ms or 1000 ms maybe, you're calling it 0.1sec btw
And also this timer always on because of 1 val ( true ), ( maybe this is why you call it infinite loop )
Re: Infinite loop that freezes the server -
AliveBG - 22.05.2015
Same. Something (I think those infinite loops) makes the server freeze.