run time error 4
#1

The nativechecker gives me this error in server_log.txt
What can I do to fix it?
PHP код:
[14:31:02] [debugRun time error 4"Array index out of bounds"
[14:31:02] [debug]  Accessing element at index 9 past array upper bound 8
[14:31:02] [debugAMX backtrace:
[
14:31:02] [debug#0 0028b788 in ?? (1) from gm.amx
[14:31:02] [debug#1 00064754 in ?? (1) from gm.amx
[14:31:02] [debug#2 00017eb8 in public OnVehicleSpawn (1) from gm.amx
[14:31:02] [debug#3 native SetVehicleToRespawn () from samp-server.exe
[14:31:02] [debug#4 00057750 in ?? () from gm.amx
[14:31:02] [debug#5 000175c0 in public RL_OnGameModeInit () from gm.amx
[14:31:02] [debug#6 native CallLocalFunction () from samp-server.exe
[14:31:02] [debug#7 0000ad6c in public zcmd_OnGameModeInit () from gm.amx
[14:31:02] [debug#8 native CallLocalFunction () from samp-server.exe
[14:31:02] [debug#9 00009250 in public SSCANF_OnGameModeInit () from gm.amx
[14:31:02] [debug#10 000035b8 in public Itter_OnGameModeInit () from gm.amx
[14:31:02] [debug#11 native CallLocalFunction () from samp-server.exe
[14:31:02] [debug#12 00002874 in public ScriptInit_OnGameModeInit () from gm.amx
[14:31:02] [debug#13 000017f8 in public OnGameModeInit () from gm.amx 
OnVehicleSpawn code
PHP код:
public OnVehicleSpawn(vehicleid)
{
    
//new vehplatestr[128];
    //format(vehplatestr, sizeof vehplatestr, "T:RP %i", vehicleid);
    //SetVehicleNumberPlate(vehicleid, vehplatestr);
    
if(vehicleid != 509 && vehicleid != 481 && vehicleid != 510)
    {
        
SetVehicleParamsEx(vehicleid0000000);
        foreach(
Playeri)
        {
            if(
vehicleid == PlayerInfo[i][pVeh])
            {
                if(
PlayerInfo[i][vLocked]) SetVehicleParamsEx(vehicleid0001000);
                
ChangeVehiclePaintjob(PlayerInfo[i][pVeh], PlayerInfo[i][vPJ]);
                for(new 
x=0x<14i++)
                {
                    
AddVehicleComponent(PlayerInfo[i][pVeh], PlayerInfo[i][pVehMod][x]);
                }
            }
            if(
vehicleid == PlayerInfo[i][pVVeh])
            {
                if(
PlayerInfo[i][vVLocked]) SetVehicleParamsEx(vehicleid0001000);
                
ChangeVehiclePaintjob(PlayerInfo[i][pVVeh], PlayerInfo[i][vVPJ]);
                for(new 
x=0x<14i++)
                {
                    
AddVehicleComponent(PlayerInfo[i][pVVeh], PlayerInfo[i][pVVehMod][x]);
                }
            }
            if(
vehicleid == PlayerInfo[i][pBVeh])
            {
                if(
PlayerInfo[i][vBLocked]) SetVehicleParamsEx(vehicleid0001000);
                
ChangeVehiclePaintjob(PlayerInfo[i][pBVeh], PlayerInfo[i][vBPJ]);
                for(new 
x=0x<14i++)
                {
                    
AddVehicleComponent(PlayerInfo[i][pBVeh], PlayerInfo[i][pBVehMod][x]);
                }
            }
        }
        if(
IsTruckerVehicle(vehicleid))
        {
            
TruckPackages[vehicleid] = -1;
        }
        if(
Siren[vehicleid])
        {
            
Siren[vehicleid] = 0;
            
DestroyDynamicObject(SirenObject[vehicleid]);
            
DestroyDynamicObject(LightObject1[vehicleid]);
        }
    }
    return 
1;

public RL_OnGameModeInit code
PHP код:
public OnGameModeInit()
{
    
RL_OPUP = (funcidx("RL_OnPlayerUpdate") != -1);
    
RL_OPSC = (funcidx("RL_OnPlayerStateChange") != -1);
    
RL_OPKSC = (funcidx("RL_OnPlayerKeyStateChange") != -1);
    
RL_OPC = (funcidx("RL_OnPlayerConnect") != -1);
    return (
funcidx("RL_OnGameModeInit") != -1)?CallLocalFunction("RL_OnGameModeInit",""):1;
}
#if defined _ALS_OnGameModeInit
    #undef OnGameModeInit
#else
    #define _ALS_OnGameModeInit
#endif
#define OnGameModeInit RL_OnGameModeInit
forward RL_OnGameModeInit(); 
zcmd_OnGameModeInit code
PHP код:
public OnGameModeInit()
{
    
zcmd_g_HasOPCS funcidx("OnPlayerCommandReceived") != -1;
    
zcmd_g_HasOPCE funcidx("OnPlayerCommandPerformed") != -1;
    if (
funcidx("zcmd_OnGameModeInit") != -1)
    {
        return 
CallLocalFunction("zcmd_OnGameModeInit""");
    }
    return 
1;
}
#if defined _ALS_OnGameModeInit
    #undef OnGameModeInit
#else
    #define _ALS_OnGameModeInit
#endif
#define OnGameModeInit zcmd_OnGameModeInit
forward zcmd_OnGameModeInit(); 
Reply
#2

Add this to the top of OnVehicleSpawn:
PHP код:
public OnVehicleSpawn(vehicleid
{
    if (
vehicleid || vehicleid == INVALID_VEHICLE_ID) return 1;
    
// Rest of code
    
return 1;

And make sure all "vehicleid" variables(eg. "TruckPackages", "PlayerInfo[i][pVeh]") are initialised as MAX_VEHICLES in size.
Reply
#3

Quote:
Originally Posted by Virtual1ty
Посмотреть сообщение
Add this to the top of OnVehicleSpawn:
PHP код:
public OnVehicleSpawn(vehicleid
{
    if (
vehicleid || vehicleid == INVALID_VEHICLE_ID) return 1;
    
// Rest of code
    
return 1;

And make sure all "vehicleid" variables(eg. "TruckPackages", "PlayerInfo[i][pVeh]") are initialised as MAX_VEHICLES in size.
Can you make me the code please?
Reply
#4

still the same error:
PHP код:
[15:13:35] [debugRun time error 4"Array index out of bounds"
[15:13:35] [debug]  Accessing element at index 9 past array upper bound 8
[15:13:35] [debugAMX backtrace:
[
15:13:35] [debug#0 0028b7ec in ?? (1) from gm.amx
[15:13:35] [debug#1 000647b8 in ?? (1) from gm.amx
[15:13:35] [debug#2 00017eb8 in public OnVehicleSpawn (1) from gm.amx
[15:13:35] [debug#3 native SetVehicleToRespawn () from samp-server.exe
[15:13:35] [debug#4 00057750 in ?? () from gm.amx
[15:13:35] [debug#5 000175c0 in public RL_OnGameModeInit () from gm.amx
[15:13:35] [debug#6 native CallLocalFunction () from samp-server.exe
[15:13:35] [debug#7 0000ad6c in public zcmd_OnGameModeInit () from gm.amx
[15:13:35] [debug#8 native CallLocalFunction () from samp-server.exe
[15:13:35] [debug#9 00009250 in public SSCANF_OnGameModeInit () from gm.amx
[15:13:35] [debug#10 000035b8 in public Itter_OnGameModeInit () from gm.amx
[15:13:35] [debug#11 native CallLocalFunction () from samp-server.exe
[15:13:35] [debug#12 00002874 in public ScriptInit_OnGameModeInit () from gm.amx
[15:13:35] [debug#13 000017f8 in public OnGameModeInit () from gm.amx 
Reply
#5

bump
Reply
#6

Compile with -d3 flag to get more information such as functions' name and lines.

From the looks of it, it seems the run time error is caused in IsTruckerVehicle function.
Reply
#7

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Compile with -d3 flag to get more information such as functions' name and lines.

From the looks of it, it seems the run time error is caused in IsTruckerVehicle function.
Result:
PHP код:
Pawn compiler 3.2.3664              Copyright (c1997-2006ITB CompuPhase
Header size
:          25432 bytes
Code size
:          3457228 bytes
Data size
:         48760476 bytes
Stack
/heap size:      16384 bytesestimated maxusageunknowndue to recursion
Total requirements
:52259520 bytes 
Reply
#8

Since you've compiled with debug info just wait for the run time error to occur again and in the server log you'll get more information from crashdetect plugin. Post that part and the code from IsTruckerVehicle function.
Reply
#9

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Since you've compiled with debug info just wait for the run time error to occur again and in the server log you'll get more information from crashdetect plugin. Post that part and the code from IsTruckerVehicle function.
server_log.txt
PHP код:
[23:25:17] [debugRun time error 4"Array index out of bounds"
[23:25:17] [debug]  Accessing element at index 9 past array upper bound 8
[23:25:17] [debugAMX backtrace:
[
23:25:17] [debug#0 00334408 in IsTruckerVehicle (vehicleid=1) at C:\Users\Brooks\Desktop\test\gamemodes\gm.pwn:48371
[23:25:17] [debug#1 0007e824 in ?? (... <1 argument>) at C:\Users\Brooks\Desktop\test\gamemodes\gm.pwn:7634
[23:25:17] [debug#2 0001cbe0 in public OnVehicleSpawn (vehicleid=1) at C:\Users\Brooks\Desktop\test\pawno\include\YSI\y_hooks/impl.inc:798
[23:25:17] [debug#3 native SetVehicleToRespawn () from samp-server.exe
[23:25:17] [debug#4 0006e0b0 in ?? () at C:\Users\Brooks\Desktop\test\gamemodes\gm.pwn:6121
[23:25:17] [debug#5 0001c1b8 in public RL_OnGameModeInit () at C:\Users\Brooks\Desktop\test\pawno\include\YSI\y_hooks/impl.inc:484
[23:25:17] [debug#6 native CallLocalFunction () from samp-server.exe
[23:25:17] [debug#7 0000cb30 in public zcmd_OnGameModeInit () at C:\Users\Brooks\Desktop\test\pawno\include\OPSP.inc:240
[23:25:17] [debug#8 native CallLocalFunction () from samp-server.exe
[23:25:17] [debug#9 0000aa18 in public SSCANF_OnGameModeInit () at C:\Users\Brooks\Desktop\test\pawno\include\zcmd.inc:68
[23:25:17] [debug#10 000040bc in public Itter_OnGameModeInit () at C:\Users\Brooks\Desktop\test\pawno\include\sscanf2.inc:205
[23:25:17] [debug#11 native CallLocalFunction () from samp-server.exe
[23:25:17] [debug#12 00003008 in public ScriptInit_OnGameModeInit () at C:\Users\Brooks\Desktop\test\pawno\include\YSI\y_iterate.inc:791
[23:25:17] [debug#13 00001c28 in public OnGameModeInit () at C:\Users\Brooks\Desktop\test\pawno\include\YSI\internal\..\y_scriptinit.inc:171 
IsTruckerVehicle code
PHP код:
stock IsTruckerVehicle(vehicleid)
{
    for(new 
i=0i<10i++)
    {
        if(
vehicleid == JobInfo[JOB_TRUCKER][jCars][i]) return 1;
    }
    return 
0;

Reply
#10

jCars (in the enum) has a size of 9 so in the loop you need to change 10 to 9.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)