Infinite loop that freezes the server
#1

Hello,
I have a problem with infinite loops. Where do you think is the cause of infinite loop here:
PHP код:
public SpeedoUpdate()
{
    for(new 
0GetPlayerPoolSize(); <= ji++)
    {
        if(
IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))
        {
            new 
Float:xFloat:yFloat:zFloat:hpstring[24], vehicleid GetPlayerVehicleID(i);
            if(
Speedo[i] == 0)
            {
                
TextDrawShowForPlayer(ivspeed[i]);
                if(
GetVehicleModel(vehicleid) != 509 && GetVehicleModel(vehicleid) != 481 && GetVehicleModel(vehicleid) != 510)
                {
                    
TextDrawShowForPlayer(ivhealth[i]);
                }
            }
            
GetVehicleVelocity(vehicleidxyz);
            
GetVehicleHealth(vehicleidhp);
            if(
Kmhmph[i] == 0)
            {
                
format(stringsizeof(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.3499991.299996);
                
TextDrawColor(vspeed[i], 0xC3C3C3FF);
                
TextDrawSetOutline(vspeed[i], 1);
                
TextDrawSetProportional(vspeed[i], 1);
            }
            if(
Kmhmph[i] == 1)
            {
                
format(stringsizeof(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.3499991.299996);
                
TextDrawColor(vspeed[i], 0xC3C3C3FF);
                
TextDrawSetOutline(vspeed[i], 1);
                
TextDrawSetProportional(vspeed[i], 1);
            }
            
format(stringsizeof(string), "Health: %d"floatround(hp));
            
TextDrawSetString(vhealth[i], string);
            
TextDrawBackgroundColor(vhealth[i], 369098796);
            
TextDrawFont(vhealth[i], 2);
            
TextDrawLetterSize(vhealth[i], 0.3499991.299996);
            
TextDrawColor(vhealth[i], 0xC3C3C3FF);
            
TextDrawSetOutline(vhealth[i], 1);
            
TextDrawSetProportional(vhealth[i], 1);
            if(
Speedo[i] == 1)
            {
                
TextDrawHideForPlayer(ivspeed[i]);
                
TextDrawHideForPlayer(ivhealth[i]);
            }
        }
        if(!
IsPlayerInAnyVehicle(i))
        {
            
TextDrawHideForPlayer(ivspeed[i]);
            
TextDrawHideForPlayer(ivhealth[i]);
        }
    }

and
PHP код:
public Production()
{
    for(new 
0GetPlayerPoolSize(); <= ji++)
    {
        if(
IsPlayerConnected(i))
        {
            if(
pusedrug[i] == 1) {
            
SetPlayerArmedWeapon(i9);
            
SetPlayerWeather(i19); }
            if(
pusedrug[i] == 2) {
            
SetPlayerArmedWeapon(i9);
            
SetPlayerWeather(i, -74); }
            if(
pusedrug[i] == 3) {
            
SetPlayerArmedWeapon(i9);
            
SetPlayerWeather(i9); }
            if(
pusedrug[i] == 4) {
            
SetPlayerArmedWeapon(i9);
            
SetPlayerWeather(i, -130); }
        }
    }

Reply
#2

There isn't any infinite loop on those. You better look for while loops.
Reply
#3

Hmm,
PHP код:
[12:56:11] [debugAMX 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] [debugAMX 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] [debugAMX 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 0MAX_VEHICLESi++)
    {
        if(
IsGodCar[i] == 1)
        {
            
SetVehicleHealth(i1000);
        }
    }
    return 
1;

Reply
#4

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.
Reply
#5

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 0GetPlayerPoolSize(); <= ji++) // From Production() 
25332:
PHP код:
for___loop(new 0GetPlayerPoolSize(); <= ji++) // From SpeedoUpdate() 
Reply
#6

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).
Reply
#7

Where you call onspedoupddate?
Reply
#8

OnGameModeInit:
productiontimer = SetTimer("Production", 100, 1);
speedotimer = SetTimer("SpeedoUpdate", 100, 1);
Reply
#9

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 )
Reply
#10

Same. Something (I think those infinite loops) makes the server freeze.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)