SA-MP Forums Archive
"Array index out of bounds" - CrashDetect/Teritories - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: "Array index out of bounds" - CrashDetect/Teritories (/showthread.php?tid=358393)



"Array index out of bounds" - CrashDetect/Teritories - Edvin - 10.07.2012

Hi all.

I have some teritories on my gangs, and when i load it, crashdetect print me this:
Код:
[21:17:17] [debug] Run time error 4: "Array index out of bounds"
[21:17:17] [debug]   Accessing element at index 6 past array upper bound 5
[21:17:17] [debug] Backtrace:
[21:17:17] [debug] #0  000c6f44 in public OnQueryFinish (query[]=@0x002433e8 "", resultid=37, extraid=-1, connectionHandle=1) at D:\RAS\RAS\Build 25\gamemodes\RAS.pwn:15475
Line: 15475:
Код:
mysql_get_field( "minx", terField );	Teritories[ X ][ minx ] 	= floatstr( terField );
All mysql thread:
Код:
case THREAD_LOAD_TERITORIES:
		{
		    mysql_store_result( );
		    
		    new
		        terField[ 56 ],
		        X
			;

			while( mysql_retrieve_row( ) )
			{
			    mysql_get_field( "Key", terField ); 	X = strval( terField );
				mysql_get_field( "minx", terField );	Teritories[ X ][ minx ] 	= floatstr( terField );
				mysql_get_field( "miny", terField );	Teritories[ X ][ miny ] 	= floatstr( terField );
				mysql_get_field( "maxx", terField );	Teritories[ X ][ maxx ] 	= floatstr( terField );
				mysql_get_field( "maxy", terField );	Teritories[ X ][ maxy ] 	= floatstr( terField );
				mysql_get_field( "owner", terField );	Teritories[ X ][ owner ] 	= strval( terField );
				
				Teritories[ X ][ ID ] = GangZoneCreate( Teritories[ X ][ minx ], Teritories[ X ][ miny ], Teritories[ X ][ maxx ], Teritories[ X ][ maxy ] );
			}
			printf( "%d Teritories Loaded.", mysql_num_rows( ) );
			mysql_free_result( );
		}
Any ideas?


Respuesta: "Array index out of bounds" - CrashDetect/Teritories - Siralos - 10.07.2012

Your table has 6 territories with Keys 1,2,3,4,5,6
Your array has 6 slots, 0,1,2,3,4,5

Then, when you retrieve the sixth territory, the array is out of bounds.
You should use X = strval( terField ) - 1; instead of X = strval( terField );


Re: "Array index out of bounds" - CrashDetect/Teritories - Edvin - 10.07.2012

Oh, yea ) i have #define MAX_TERITORIES 6 ... xD

Problem solved, thanks !