Timer freeze bug + lag
#1

Hello!
I have a pretty bad bug in server , when i drive a vehicle ( mostly ) a public function freezes, i use a timer to call it each 1010 miliseconds, it's Checkvehinfo ( for realtime speed, odometer, fuel, status + auto car fix for admins )
so when it freezes it doesn't auto fix anymore and speed stops at a number ( not always but mostly )
when i checked server log i found this error detected by crashdetect every second ( 1010 ms ):
Код:
[16:30:03] [debug] AMX backtrace:
[16:30:03] [debug] #0 0010987c in public Checkvehinfo () from Blast.amx
[16:30:04] [debug] Run time error 4: "Array index out of bounds"
[16:30:04] [debug]  Accessing element at negative index -1
***** after 1 sec *****
[16:30:04] [debug] AMX backtrace:
[16:30:04] [debug] #0 0010987c in public Checkvehinfo () from Blast.amx
[16:30:05] [debug] Run time error 4: "Array index out of bounds"
[16:30:05] [debug]  Accessing element at negative index -1
server log is fully spammed xD,
here is the public function :
PHP код:
public Checkvehinfo()
{
    foreach(
Player,i)
    {
        if(
IsPlayerConnected(i))
           {
            if(
PlayerInfo[i][pAdmin] >= 1RepairVehicle(GetPlayerVehicleID(i));
            new 
carid HireCar[i];
               if(
GetPlayerState(i) == PLAYER_STATE_DRIVER)
               {
                   new 
vehicle GetPlayerVehicleID(i),
                 
spe Carspeed(i);
                new 
str1[128],str2[128],str3[128],str4[128],str5[128],str6[128];
                
PlayerTextDrawShow(iSpeedd[i]);
                
format(str1,sizeof(str1)," Speed: ~y~%d Km/h",spe);
                
PlayerTextDrawSetString(iSpeedd[i], str1); // sa facem si la bicicleta
                
if(SwitchKey[i] == && gCarLock[carid] == 1)
                {
                       
PlayerTextDrawShow(iFuell[i]);
                    
format(str2,sizeof(str2),"Fuel: ~y~%d"Gas[vehicle]);
                    
PlayerTextDrawSetString(iFuell[i], str2);
                    
PlayerTextDrawShow(icarlocked[i]);
                      
format(str3,sizeof(str3),"~y~LOCKED");
                    
PlayerTextDrawSetString(icarlocked[i], str3);
                }
                if(
SwitchKey[i] == && gCarLock[carid] == 0)
                {
                       
PlayerTextDrawShow(iFuell[i]);
                    
format(str2,sizeof(str2),"Fuel: ~y~%d"Gas[vehicle]);
                    
PlayerTextDrawSetString(iFuell[i], str2);
                    
PlayerTextDrawShow(icarlocked[i]);
                    
format(str3,sizeof(str3), "UNLOCKED");
                    
PlayerTextDrawSetString(icarlocked[i], str3);
                }
                if(
IsABike(vehicle) && SwitchKey[i] != 2)
                {
                    
PlayerTextDrawShow(iSpeedd[i]);
                    
format(str1,sizeof(str1)," Speed: ~y~%d Km/h",spe);
                    
PlayerTextDrawSetString(iSpeedd[i], str1);
                    
PlayerTextDrawShow(ibikeunlocked[i]);
                    
format(str6,sizeof(str6), "UNLOCKED");
                    
PlayerTextDrawSetString(ibikeunlocked[i], str6);
                }
                else if(!
IsABike(vehicle) && !OwnedVeh(vehicle) && SwitchKey[i] != 2)
                {
                    
PlayerTextDrawShow(iFuell[i]);
                    
format(str2,sizeof(str2),"Fuel: ~y~%d"Gas[vehicle]);
                    
PlayerTextDrawSetString(iFuell[i], str2);
                    
PlayerTextDrawShow(iunlocked[i]);
                    
format(str6,sizeof(str6), "UNLOCKED");
                    
PlayerTextDrawSetString(iunlocked[i], str6);
                }
                if(
OwnedVeh(vehicle) != && !IsAPlane(vehicle) && !IsABike(vehicle) && SwitchKey[i] != 2)
                {
                       
PlayerTextDrawShow(iFuell[i]);
                    
format(str2,sizeof(str2),"Fuel: ~y~%d"Gas[vehicle]);
                    
PlayerTextDrawSetString(iFuell[i], str2);
                    
PlayerTextDrawShow(iOdom[i]);
                    
format(str3,sizeof(str3),"Odometer: ~y~%.0fKM",CarInfo[OwnedVeh(vehicle)][cKM]);
                    
PlayerTextDrawSetString(iOdom[i], str3);
                }
                if(
OwnedVeh(vehicle) != && CarInfo[OwnedVeh(vehicle)][cLock] == && SwitchKey[i] != 2)
                {
                    
PlayerTextDrawShow(icarlocked[i]);
                    
format(str4,sizeof(str4),"UNLOCKED");
                    
PlayerTextDrawSetString(icarlocked[i], str4);
                }
                else if(
OwnedVeh(vehicle) != && CarInfo[OwnedVeh(vehicle)][cLock] == && SwitchKey[i] != 2)
                {
                    
PlayerTextDrawShow(icarlocked[i]);
                    
format(str5,sizeof(str5),"~y~LOCKED");
                    
PlayerTextDrawSetString(icarlocked[i], str5);
                }
            }
            else if(
GetPlayerState(i) == PLAYER_STATE_PASSENGER)
               {
                   new 
count;
                   foreach(
Playerx)
                {
                    if(
GetPlayerState(x) == PLAYER_STATE_PASSENGER)
                       {
                           if(
GetPlayerVehicleID(x) == GetPlayerVehicleID(i))
                           {
                               
count ++;
                        }
                    }
                    if(
count >= 1)
                    {
                        new 
vehicle GetPlayerVehicleID(i),
                            
spe Carspeed(i);
                            new 
str1[128],str2[128],str3[128],str4[128],str5[128],str6[128];
                        
PlayerTextDrawShow(iSpeedd[i]);
                        
format(str1,sizeof(str1)," Speed: ~y~%d Km/h",spe);
                        
PlayerTextDrawSetString(iSpeedd[i], str1);
                        if(
SwitchKey[i] == && gCarLock[carid] == 1)
                        {
                               
PlayerTextDrawShow(iFuell[i]);
                            
format(str2,sizeof(str2),"Fuel: ~y~%d"Gas[vehicle]);
                            
PlayerTextDrawSetString(iFuell[i], str2);
                            
PlayerTextDrawShow(icarlocked[i]);
                              
format(str3,sizeof(str3),"~y~LOCKED");
                            
PlayerTextDrawSetString(icarlocked[i], str3);
                        }
                        if(
SwitchKey[i] == && gCarLock[carid] == 0)
                        {
                               
PlayerTextDrawShow(iFuell[i]);
                            
format(str2,sizeof(str2),"Fuel: ~y~%d"Gas[vehicle]);
                            
PlayerTextDrawSetString(iFuell[i], str2);
                            
PlayerTextDrawShow(icarlocked[i]);
                            
format(str3,sizeof(str3), "UNLOCKED");
                            
PlayerTextDrawSetString(icarlocked[i], str3);
                        }
                        if(!
IsABike(vehicle) && SwitchKey[i] != 2// trebuie sa facem alt tw pt bike la unlcoked?da, sa l
                        
{
                            
PlayerTextDrawShow(iFuell[i]);
                            
format(str2,sizeof(str2),"Fuel: ~y~%d"Gas[vehicle]);
                            
PlayerTextDrawSetString(iFuell[i], str2);
                            
format(str4,sizeof(str4),"UNLOCKED");
                            
PlayerTextDrawShow(iunlocked[i]);
                            
format(str6,sizeof(str6), "UNLOCKED");
                            
PlayerTextDrawSetString(iunlocked[i], str6);
                        }
                        if(
OwnedVeh(vehicle) != && !IsAPlane(vehicle) && SwitchKey[i] != 2)
                        {
                            
PlayerTextDrawShow(iOdom[i]);
                            
format(str3,sizeof(str3),"Odometer: ~y~%.0fKM",CarInfo[OwnedVeh(vehicle)][cKM]);
                            
PlayerTextDrawSetString(iOdom[i], str3);
                        }
                        if(
OwnedVeh(vehicle) != && CarInfo[OwnedVeh(vehicle)][cLock] == && SwitchKey[i] != 2)
                        {
                            
PlayerTextDrawShow(icarlocked[i]);
                            
format(str4,sizeof(str4),"UNLOCKED");
                            
PlayerTextDrawSetString(icarlocked[i], str4);
                        }
                        else if(
OwnedVeh(vehicle) != && CarInfo[OwnedVeh(vehicle)][cLock] == && SwitchKey[i] != 2)
                        {
                            
PlayerTextDrawShow(icarlocked[i]);
                            
format(str5,sizeof(str5),"~y~LOCKED");
                            
PlayerTextDrawSetString(icarlocked[i], str5);
                        }
                    }
                    else if(
count 1)
                    {
                        
PlayerTextDrawHide(iFuell[i]);
                           
PlayerTextDrawHide(iSpeedd[i]);
                           
PlayerTextDrawHide(icarlocked[i]);
                           
PlayerTextDrawHide(iOdom[i]);
                           
PlayerTextDrawHide(iunlocked[i]);
                    }
                }
            }
            else if(
GetPlayerState(i) != PLAYER_STATE_DRIVER && GetPlayerState(i) != PLAYER_STATE_PASSENGER)
            {
                   
PlayerTextDrawHide(iFuell[i]);
                
PlayerTextDrawHide(iSpeedd[i]);
                
PlayerTextDrawHide(icarlocked[i]);
                
PlayerTextDrawHide(iOdom[i]);
                
PlayerTextDrawHide(iunlocked[i]);
                
PlayerTextDrawHide(ibikeunlocked[i]);
            }
        }
    }
    return 
1;

thanks, i apperciate any kind of help/advice.
Reply
#2

Compile with debud flag -d3 and get the exact line for that thing.
Reply
#3

how? ( sorry for noob question )
Reply
#4

https://github.com/Zeex/samp-plugin-...ith-debug-info
Reply
#5

Ok i'll edit the reply with debug results when it's compiled. ( 68k lines xD )
Reply
#6

it won't compile ( yet )
EDIT: Pawno isn't responding for over 10mins
Reply
#7

Here is it ( finally )

The text that isn't appearing:
Код:
(153504 bytes)
Reply
#8

Drive a vehicle... and paste the text here when it appears in console.
Reply
#9

Now i understood you...
here's the output:
Код:
[20:23:06] [debug] AMX backtrace:
[20:23:06] [debug] #0 001520c0 in public Checkvehinfo () at C:\Documents and Settings\NoName\Bureau\rpg\gamemodes\Blast.pwn:20335
[20:23:08] [debug] Run time error 4: "Array index out of bounds"
[20:23:08] [debug]  Accessing element at negative index -1
[20:23:08] [debug] AMX backtrace:
[20:23:08] [debug] #0 001520c0 in public Checkvehinfo () at C:\Documents and Settings\NoName\Bureau\rpg\gamemodes\Blast.pwn:20335
[20:23:11] ADMIN: Done
And here is the line 20335 :
PHP код:
public Checkvehinfo()
{
    foreach(
Player,i)
    {
        if(
IsPlayerConnected(i))
           {
            if(
PlayerInfo[i][pAdmin] >= 1RepairVehicle(GetPlayerVehicleID(i));
            new 
carid HireCar[i];
               if(
GetPlayerState(i) == PLAYER_STATE_DRIVER)
               {
                   new 
vehicle GetPlayerVehicleID(i),
                 
spe Carspeed(i);
                new 
str1[128],str2[128],str3[128],str4[128],str5[128],str6[128];
                
PlayerTextDrawShow(iSpeedd[i]);
                
format(str1,sizeof(str1)," Speed: ~y~%d Km/h",spe);
                
PlayerTextDrawSetString(iSpeedd[i], str1);
      
/* ---> */if(SwitchKey[i] == && gCarLock[carid] == 1)
                {
                       
PlayerTextDrawShow(iFuell[i]);
                    
format(str2,sizeof(str2),"Fuel: ~y~%d"Gas[vehicle]);
                    
PlayerTextDrawSetString(iFuell[i], str2);
                    
PlayerTextDrawShow(icarlocked[i]);
                      
format(str3,sizeof(str3),"~y~LOCKED");
                    
PlayerTextDrawSetString(icarlocked[i], str3);
                }
                if(
SwitchKey[i] == && gCarLock[carid] == 0)
                {
                       
PlayerTextDrawShow(iFuell[i]);
                    
format(str2,sizeof(str2),"Fuel: ~y~%d"Gas[vehicle]);
                    
PlayerTextDrawSetString(iFuell[i], str2);
                    
PlayerTextDrawShow(icarlocked[i]);
                    
format(str3,sizeof(str3), "UNLOCKED");
                    
PlayerTextDrawSetString(icarlocked[i], str3);
                } ... 
Reply
#10

PHP код:
new carid HireCar[i]; 
it seems like this providing -1 value to to carid. You should either make an exception statement for this situation (value becoming negative) can be achieved using a simple if statement. Or you have to fix the logic you implemented there.

Further more:
Update to latest foreach
foreach iterates through connected players so checking the player is connected is not required
don't declare variables inside the loop structure.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)