Raised This Month: $32 Target: $400
 8% 

Run time error 4: index out of bounds


Post New Thread Reply   
 
Thread Tools Display Modes
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 05-21-2023 , 18:27   Re: Run time error 4: index out of bounds
Reply With Quote #11

Quote:
Originally Posted by Natsheh View Post
Your problem is here

GoalEnt[team]

In the variable team since the ball touch function is called depending on the player fps, its high likely to get an invalid team at some time to fix the problem simply add a check

PHP Code:

new golentteam;

if(
ballowner 0team get_user_team(ballowner);
if(
team >= && team sizeof GoalEntgolent GoalEnt[team]; 
Where should I put that or what should I replace with that?
JuanitoAlimana is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-21-2023 , 19:40   Re: Run time error 4: index out of bounds
Reply With Quote #12

Quote:
Originally Posted by JuanitoAlimana View Post
Plugin works fine, no index out of bounds error.
Server console shows these 3 messages several times in a random order:
L 05/21/2023 - 05:26:00: [Sj-Pro-debug.amxx] ballowner set to zero in touchPlayer()
L 05/21/2023 - 05:26:07: [Sj-Pro-debug.amxx] ballowner set to zero in moveBall()
L 05/21/2023 - 05:429: [Sj-Pro-debug.amxx] ballowner set to zero in client_disconnected()
You need to provide the plugin error also so that they can be time correlated. I've added a couple more debug logs to the plugin so please re-download it here.

Quote:
Originally Posted by Natsheh View Post
Your problem is here

GoalEnt[team]

In the variable team since the ball touch function is called depending on the player fps, its high likely to get an invalid team at some time to fix the problem simply add a check

PHP Code:

new golentteam;

if(
ballowner 0team get_user_team(ballowner);
if(
team >= && team sizeof GoalEntgolent GoalEnt[team]; 
The issue is much bigger than this. If you even do get past this one check, there are many more things that will go wrong.
__________________
fysiks is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 05-23-2023 , 13:24   Re: Run time error 4: index out of bounds
Reply With Quote #13

Quote:
Originally Posted by fysiks View Post
You need to provide the plugin error also so that they can be time correlated. I've added a couple more debug logs to the plugin so please re-download it here.



The issue is much bigger than this. If you even do get past this one check, there are many more things that will go wrong.
That is likely to happen if the author is not careful with indexing an array.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-24-2023 , 00:41   Re: Run time error 4: index out of bounds
Reply With Quote #14

Quote:
Originally Posted by Natsheh View Post
That is likely to happen if the author is not careful with indexing an array.
I know how index out of bounds works. However, in this case, it's not as simple as just a single wrong index because of how that variable is used is many places.
__________________

Last edited by fysiks; 05-24-2023 at 00:45.
fysiks is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 05-24-2023 , 08:50   Re: Run time error 4: index out of bounds
Reply With Quote #15

what if the last ballowner is stored in a global variable that will be accesed when the "goal event" is triggered?
lexzor is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-24-2023 , 23:01   Re: Run time error 4: index out of bounds
Reply With Quote #16

Quote:
Originally Posted by lexzor View Post
what if the last ballowner is stored in a global variable that will be accesed when the "goal event" is triggered?
That won't work because if that player disconnects and/or someone else then connects and gets that same id the data will be either invalid or wrong.

However, a similar option is to create a "generic" ballowner where you store just which team had the ball last and if the ballowner doesn't exist, use just which team scored the goal. This would mean you'd need to modify the code to skip any player-specific functions if the ballowner is zero and instead use generic data about the team.
__________________
fysiks is offline
JuanitoAlimana
Senior Member
Join Date: Aug 2021
Old 05-25-2023 , 02:21   Re: Run time error 4: index out of bounds
Reply With Quote #17

Quote:
Originally Posted by fysiks View Post
You need to provide the plugin error also so that they can be time correlated. I've added a couple more debug logs to the plugin so please re-download it here.



The issue is much bigger than this. If you even do get past this one check, there are many more things that will go wrong.
This is all the console shows:
02:17:09: [Sj-Pro-debug.amxx] ballowner set to zero in touchPlayer()
02:17:12: [Sj-Pro-debug.amxx] ballowner set to zero in touchPlayer()
02:17:12: [Sj-Pro-debug.amxx] touchNet(), ballowner = 0
02:17:12: [Sj-Pro-debug.amxx] touchNet(), team = -1
02:17:12: [AMXX] Displaying debug trace (plugin "Sj-Pro-debug.amxx", version "6.0b-debug")
02:17:12: [AMXX] Run time error 4: index out of bounds
02:17:12: [AMXX] [0] Sj-Pro-debug.sma::touchNet (line 1895)
02:17:58: [Sj-Pro-debug.amxx] ballowner set to zero in touchPlayer()
02:17:58: [Sj-Pro-debug.amxx] ballowner set to zero in touchPlayer()
02:17:59: [Sj-Pro-debug.amxx] touchNet(), ballowner = 13
02:17:59: [Sj-Pro-debug.amxx] touchNet(), team = 1
02:17:59: [Sj-Pro-debug.amxx] touchNet(), golent = 75
02:18:55: [Sj-Pro-debug.amxx] ballowner set to zero in touchPlayer()
02:18:56: [Sj-Pro-debug.amxx] ballowner set to zero in touchPlayer()
02:18:56: [Sj-Pro-debug.amxx] ballowner set to zero in touchPlayer()
02:18:57: [Sj-Pro-debug.amxx] ballowner set to zero in touchPlayer()
02:18:58: [Sj-Pro-debug.amxx] ballowner set to zero in touchPlayer()
02:19:00: [Sj-Pro-debug.amxx] touchNet(), ballowner = 4
02:19:00: [Sj-Pro-debug.amxx] touchNet(), team = 2
02:19:00: [Sj-Pro-debug.amxx] touchNet(), golent = 74

Everything works perfectly, by the way, no crashes, no bugs, just the annoying index out of bounds error from time to time.

Last edited by JuanitoAlimana; 05-25-2023 at 02:22.
JuanitoAlimana is offline
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

Forum Jump


All times are GMT -4. The time now is 18:53.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode