SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 12/01/2020, 02:12 PM   #1
Vizi10
Huge Clucker
 
Join Date: May 2017
Location: Iran
Posts: 283
Reputation: 8
Default Crash

pawn Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new RadioURL[128];
        GetPVarString(playerid, "RadioCustomURL", RadioURL, sizeof RadioURL);
        if(gRadioUrl[playerid] != -1 || !isnull(RadioURL))
        {
            if(!isnull(RadioURL)) PlayAudioStreamForPlayer(playerid, RadioURL); //error line
            else PlayAudioStreamForPlayer(playerid, RadioOnline_Urls[ gRadioUrl[playerid]]);
        }
    }
    return 1;
}

Code:
[12/01/2020 14:54:25] [debug] Run time error 4: "Array index out of bounds"
[12/01/2020 14:54:25] [debug]  Attempted to read/write array element at index 9 in array of size 7
[12/01/2020 14:54:25] [debug] AMX backtrace:
[12/01/2020 14:54:25] [debug] #0 0022e384 in OnPlayerStateChange (playerid=18, newstate=2, oldstate=1) at desktop\cnr\include\radio.inc:100
What the problem?
Please help me.+rep
Vizi10 is offline   Reply With Quote
Old 12/01/2020, 05:09 PM   #2
Flofey
Little Clucker
 
Flofey's Avatar
 
Join Date: Oct 2018
Location: South the moon
Posts: 32
Reputation: 11
Default Re: Crash

I'm not that expert in coding but maybe you should put
PHP Code:
return 
__________________
Discord: Flofey#8478
Flofey is offline   Reply With Quote
Old 12/01/2020, 05:32 PM   #3
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 958
Reputation: 167
Default Re: Crash

Code:
RadioOnline_Urls[ gRadioUrl[playerid]]
The size of `RadioOnline_Urls` is 7.
The value of `gRadioUrl[playerid]` is 9.
Result is out-of-bounds array index.

The correct way to verify array indexes is this:
pawn Code:
if (!isnull(RadioURL))
{
    PlayAudioStreamForPlayer(playerid, RadioURL);
}
else if (0 <= gRadioUrl[playerid] < sizeof (RadioOnline_Urls))
// OR
// if (gRadioUrl[playerid] >= 0 && gRadioUrl[playerid] < sizeof (RadioOnline_Urls))
{
    PlayAudioStreamForPlayer(playerid, RadioOnline_Urls[ gRadioUrl[playerid]]);
}
While this prevent the run time error, it will never play the audio because the way you assign to `gRadioUrl[playerid]` is faulty. It does not match the number of URLs in `RadioOnline_Urls` array.
__________________
Calisthenics is offline   Reply With Quote
Old 12/01/2020, 07:03 PM   #4
Vizi10
Huge Clucker
 
Join Date: May 2017
Location: Iran
Posts: 283
Reputation: 8
Default Re: Crash

Oh, I reduced the number of links (RadioOnline_Urls) and stored `gRadioUrl[playerid]` in the database and some players radio id more than 7. So the problem was..
Thanks @Calisthenics
Vizi10 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Crash detect , server crash Debug. whats wrong? MarwanCartman Server Support 4 10/05/2015 12:14 PM
[HELP]Server Crash - Located crash line with CrashDETECT - Guest4390857394857 Server Support 4 05/09/2014 05:37 AM
setplayername server crash helpme [crash detect] bigtigerbeee Scripting Help 4 28/11/2013 01:23 AM


All times are GMT. The time now is 02:38 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.