Run time error 4: "Array index out of bounds"
#1

What's wrong with this code, any time during the race wants to start always appear bugs in the log, please help what's wrong with this code, thanks.

PHP код:
[10:42:10] [debugRun time error 4"Array index out of bounds"
[10:42:10] [debug]  Accessing element at index 64 past array upper bound 63
[10:42:10] [debugAMX backtrace:
[
10:42:10] [debug#0 001bc2b0 in public LoadRace (18179976) from GM.amx
[10:42:10] [debug#1 001b49e8 in public RaceRotation () from GM.amx 
LoadRace:
PHP код:
public LoadRace(tmp[])
{
    new 
race_name[32],templine[512];
    
format(CRaceName,sizeof(CRaceName), "%s",tmp);
    
format(race_name,sizeof(race_name), "Race/%s.yr",tmp);
    if(!
fexist(race_name)) return -1// File doesn't exist
    
CFile=race_name;
    
LCurrentCheckpoint=-1RLenght=0RLenght=0;
    new 
File:fi;
    
fopen(race_nameio_read);
    
fread(f,templine,sizeof(templine));
    if(
templine[0] == 'Y'//Checking if the racefile is v0.2+
    
{
        new 
fileversion;
        
strtok(templine,i); // read off YRACE
        
fileversion strval(strtok(templine,i)); // read off the file version
        
if(fileversion RACEFILE_VERSION) return -2// Check if the race is made with a newer version of the racefile format
        
CBuilder=strtok(templine,i); // read off RACEBUILDER
        
ORacemode strval(strtok(templine,i)); // read off racemode
        
ORacelaps strval(strtok(templine,i)); // read off amount of laps
        
if(fileversion 1)
        {
            
Airrace strval(strtok(templine,i));   // read off airrace
            
CPsize floatstr(strtok(templine,i));    // read off CP size
        
}
        else 
// v1 file format, set to default
        
{
            
Airrace 0;
            
CPsize 8.0;
        }
        
OAirrace Airrace;
        
OCPsize CPsize;
        
Racemode=ORacemodeRacelaps=ORacelaps//Allows changing the modes, but disables highscores if they've been changed.
        
fread(f,templine,sizeof(templine)); // read off best race times
        
i=0;
        for(new 
j=0;j<5;j++)
        {
            
TopRacers[j]=strtok(templine,i);
            
TopRacerTimes[j]=strval(strtok(templine,i));
        }
        
fread(f,templine,sizeof(templine)); // read off best lap times
        
i=0;
        for(new 
j=0;j<5;j++)
        {
            
TopLappers[j]=strtok(templine,i);
            
TopLapTimes[j]=strval(strtok(templine,i));
        }
    }
    else 
//Otherwise add the lines as checkpoints, the file is made with v0.1 (or older) version of the script.
    
{
        
LCurrentCheckpoint++;
        
RaceCheckpoints[LCurrentCheckpoint][0] = floatstr(strtok(templine,i));
        
RaceCheckpoints[LCurrentCheckpoint][1] = floatstr(strtok(templine,i));
        
RaceCheckpoints[LCurrentCheckpoint][2] = floatstr(strtok(templine,i));
        
Racemode=0ORacemode=0Racelaps=0ORacelaps=0;   //Enables converting old files to new versions
        
CPsize 8.0Airrace 0;              // v2 additions
        
OCPsize CPsizeOAirrace Airrace;   // v2 additions
        
CBuilder="UNKNOWN";
        for(new 
j;j<5;j++)
        {
            
TopLappers[j]="A"TopLapTimes[j]=0TopRacers[j]="A"TopRacerTimes[j]=0;
        }
    }
    while(
fread(f,templine,sizeof(templine),false))
    {
        
LCurrentCheckpoint++;
        
i=0;
        
RaceCheckpoints[LCurrentCheckpoint][0] = floatstr(strtok(templine,i));
        
RaceCheckpoints[LCurrentCheckpoint][1] = floatstr(strtok(templine,i));
        
RaceCheckpoints[LCurrentCheckpoint][2] = floatstr(strtok(templine,i));
        if(
LCurrentCheckpoint >= 1)
        {
            
RLenght+=Distance(RaceCheckpoints[LCurrentCheckpoint][0],RaceCheckpoints[LCurrentCheckpoint][1],
                                
RaceCheckpoints[LCurrentCheckpoint][2],RaceCheckpoints[LCurrentCheckpoint-1][0],
                                
RaceCheckpoints[LCurrentCheckpoint-1][1],RaceCheckpoints[LCurrentCheckpoint-1][2]);
        }
    }
    
LLenght RLenght Distance(RaceCheckpoints[LCurrentCheckpoint][0],RaceCheckpoints[LCurrentCheckpoint][1],
                                
RaceCheckpoints[LCurrentCheckpoint][2],RaceCheckpoints[0][0],RaceCheckpoints[0][1],
                                
RaceCheckpoints[0][2]);
    
fclose(f);
    return 
1;

RaceRotation:
PHP код:
public RaceRotation()
{
    if(!
fexist("Race/YRace.rr"))
    {
        
printf("ERROR in  YRACE's Race Rotation (YRace.rr): YRace.rr doesn't exist!");
        return -
1;
    }
    if(
RRotation == -1)
    {
        
KillTimer(RotationTimer);
        return -
1// RRotation has been disabled
    
}
    if(
Participants 0) return 1// A race is still active.
    
new File:ftempline[32], rotfile[]="Race/YRace.rr"rraces=-1rracenames[32][32], idxfback;
    
fopen(rotfileio_read);
    while(
fread(f,templine,sizeof(templine),false))
    {
        
idx 0;
        
rraces++;
        
rracenames[rraces]=strtok(templine,idx);
    }
    
fclose(f);
    
RRotation++;
    
RRotation %= rraces;
    
fback LoadRace(rracenames[RRotation]);
    if(
fback == -1printf("ERROR in YRACE's Race Rotation (YRace.rr): Race \'%s\' doesn't exist!",rracenames[RRotation]);
    else if (
fback == -2printf("ERROR in YRACE's Race Rotation (YRace.rr): Race \'%s\' is created with a newer version of YRACE",rracenames[RRotation]);
    else 
startrace();
//    print("Race Rotated!");
    
return 1;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)