Strange array problem on android.

Monkey Targets Forums/Android/Strange array problem on android.

AndyGFX(Posted 2011) [#1]
I have created class where i have stored matrix data:

Const SHAPES_COUNT:Int = 21

Class TShapes
	

	Field shape:String[]
	Field current_shape:Int[] = New Int[81]

	Field ball_small:TImage
		
	Method New()
				
		Self.shape = New String[SHAPES_COUNT]
		
		
		Self.shape[0] = "---X-X----X-X-X-X---XX-XX--XXX---XXX---------XXX---XXX--XX-XX---X-X-X-X----X-X--"
		Self.shape[1] = "--------X-------X-------X-------X-------X-------X-------X-------X-------X--------"
		Self.shape[2] = "XXXXXXXXXX------XXX-----X-XX----X--XX---X---XX--X----XX-X-----XXX------XXXXXXXXXX"
		Self.shape[3] = "----X-----X--X--X---X-X-X-----XXX---XXXXXXXXX---XXX-----X-X-X---X--X--X-----X----"
		Self.shape[4] = "X---X---X-X--X--X---X-X-X-----XXX---XXXXXXXXX---XXX-----X-X-X---X--X--X-X---X---X"
		Self.shape[5] = "X-------X-X-----X---X---X-----X-X---------------X-X-----X---X---X-----X-X-------X"		
		Self.shape[6] = "X-------X---------------------------------------------------------------X-------X"
		Self.shape[7] = "X-------X-X-----X-----------------------------------------------X-----X-X-------X"
		Self.shape[8] = "X--X-X--X---X-X-----XX-XX--XXX---XXX---------XXX---XXX--XX-XX-----X-X---X--X-X--"
		Self.shape[9] = "XXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXX---------XXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXX"
		Self.shape[10] = "XXXXXXXXXX-XXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXX-XXXXXXXXXX"
		Self.shape[11] = "-XXXXXXX-X-XXXXX-XXX-XXX-XXXXX-X-XXXXXXXXXXXXXXX-X-XXXXX-XXX-XXX-XXXXX-X-XXXXXXX-"
		Self.shape[12] = "XXXX-----XXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXX-----XXXX"
		Self.shape[13] = "--X--X-X--XX---XXXXX-XXXXX---X---X-X--X-X-X--X-X---X---XXXXX-XXXXX---XX--X-X--X--"
		Self.shape[14] = "--X-XX-X--XX-X-XXXXX-X-XXX---X-X-X-XXX-X-X-XXX-X-X-X---XXX-X-XXXXX-X-XX--X-XX-X--"
		Self.shape[15] = "XXXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXX-XXXXXXXX"
		Self.shape[16] = "XX-----XXXX-----XX--X---X-----X-X---------------X-X-----X---X--XX-----XXXX-----XX"
		Self.shape[17] = "XX-----XXXX-----XX--XX-XX----XX-XX-------------XX-XX----XX-XX--XX-----XXXX-----XX"
		Self.shape[18] = "XX--X--XXXX--X--XX--XXXXX----XXXXX--XXXXXXXXX--XXXXX----XXXXX--XX--X--XXXX--X--XX"
		Self.shape[19] = "XX--X--XXXX--X--XX---XXX-----X-X-X--XXXXXXXXX--X-X-X-----XXX---XX--X--XXXX--X--XX"
		Self.shape[20] = "-X-----X-XX-----XX---X-X-----X---X-------------X---X-----X-X---XX-----XX-X-----X-"
		
		
	End

	' ----------------------------------------------------------------------------------
	Method InitShapeMatrix:Void(id:Int)
	
		Local i:Int
		For Local x:Int = 0 to 8
			For Local y:Int = 0 to 8
				i = x+y*9
				If Self.shape[id][i]=88 Then
					Self.current_shape[i] = 1
				else
					Self.current_shape[i] = 0
				End if
			Next
		Next
	End
	
	' ----------------------------------------------------------------------------------
	Method DrawAt:Void(xx:Int,yy:Int)
	
		For Local x:Int = 0 to 8
			For Local y:Int = 0 to 8				
				If (Self.current_shape[x+y*9])=1 Then Self.ball_small.Draw(xx+x*16,yy+y*16,0,0.5,0.5)
			Next
		Next
	End
	
	' ----------------------------------------------------------------------------------
	Method DrawPreviewAt:Void(xx:Int,yy:Int)
		Local px:Int=0
		Local py:Int = 0
		For Local x:Int = 0 to 8
			For Local y:Int = 0 to 8				
				px = xx+x*8
				py = yy+y*8
				If (Self.current_shape[x+y*9])=1 Then 
					SetColor(255,255,255)
				Else
					SetColor(0,0,0)
				EndIf
				
				DrawRect(px,py,6,6)
			Next
		Next	
	
	End
	
End


When i call method InitShapeMatrix(0) app crash and crash too when id is =8, it's strange for me, because under all other platforms works fine.

Problem is that [0] and [8] has wrong char number in line, my main question is why is this recognizen only with java language?


muddy_shoes(Posted 2011) [#2]
Java has bounds-checking that throws an error on OOB array accesses and the other targets you've tried don't. Presumably you haven't tried XNA, because C# also throws errors on such accesses.

The other platforms don't "work fine" by the way, they just don't crash based on your current code.