Code working in html5 but not iOS or GLFW

Monkey Forums/Monkey Programming/Code working in html5 but not iOS or GLFW

Tri|Ga|De(Posted 2011) [#1]
I have some code that works okay in html5 but if I try it in iOS or GLFW it just blinks and then terminate. In X-code console there is no error shown.

Here is my code, its messy so just ignore that.


Import mojo 

Class ball
	Field ballI:Image
	Field ballX:Float
	Field ballY:Float
End

Class MyTouch Extends App

	Global touchX:Float
	Global touchY:Float
	Global SelectedBall:Int = -1
	Global touchedBall:Int = 0
	Global moveable:Int = 0
	Global startSet:Int = 0
	Global endSet:Int = 0
	Global oldX:Float
	Global oldY:Float
	Global newX:Float
	Global newY:Float
	Global moveX:Float
	Global moveY:Float
	Global speed:Float = 30.0
	Global AmigaBall:ball[]
	Global hitCounter:Int = 5
	Global direction:Int = 0

	Method OnCreate()
	
		AmigaBall[0] = New ball
		AmigaBall[1] = New ball
		
		AmigaBall[1].ballI = LoadImage("AmigaBall.png")
		AmigaBall[1].ballI.SetHandle(40, 40)
		
		AmigaBall[1].ballX = 200
		AmigaBall[1].ballY = 300

		SetUpdateRate 30
	End
	
	Method OnUpdate()
		touchX = TouchX(0)
		touchY = TouchY(0) 
		
		SelectedBall = FindImage(touchX, touchY)
		
		If TouchDown(0) And startSet = 1 And endSet = 0 And hitCounter = 0
			newX = touchX
			newY = touchY
			'** Den må flyttes
			moveable = 1
			'** Andet punkt er sat
			endSet = 1
			If newX > oldX Then direction = 2
			If newX < oldX Then direction = 1
		Endif
		If TouchDown(0) And endSet = 0 And startSet = 0 And SelectedBall > 0
			oldX = touchX
			oldY = touchY
			moveX = oldX
			moveY = oldY
			'** Sæt første punkt
			startSet = 1
			'** Sæt valgt ball som den ball som musen er hen over
			touchedBall = SelectedBall
		End If		

		If startSet = 1 And endSet = 0
			If hitCounter > 0 Then hitCounter -=1
		Endif
	End
	
	Method OnRender()
		Cls
		DrawImage AmigaBall[1].ballI, AmigaBall[1].ballX, AmigaBall[1].ballY

		DrawText "Touch=X" + touchX, 0, 10
		DrawText "TouchY=" + touchY, 0, 20
		DrawText "oldX=" + oldX, 0, 30
		DrawText "oldY=" + oldY, 0, 40
		DrawText "newX=" + newX, 0, 50
		DrawText "newY=" + newY, 0, 60
		DrawText "moveX=" + moveX, 0, 70
		DrawText "moveY=" + moveY, 0, 80
		DrawText "startSet=" + startSet, 0, 90
		DrawText "endSet=" + endSet, 0, 100
		DrawText "touchedBall=" + touchedBall, 0, 110
		DrawText "moveable=" + moveable, 0, 120
		DrawText "AmigaBall: " + SelectedBall, 0,130		

		If moveable = 1 And endSet = 1
			MoveBall(touchedBall)
		Endif
	End
	
	Method MoveBall(sBall:Int)
		'** Regn punkt y ud
		'** y = ((d-b)/(c-a)) * (x-a) + b
		moveY = ((newY-oldY)/(newX-oldX))*(moveX-oldX)+oldY
		AmigaBall[sBall].ballX = moveX
		AmigaBall[sBall].ballY = moveY
		If direction = 2
			moveX += (0.1 * speed)
			If moveX > newX
				moveable = 0
				touchedBall = 0
				startSet = 0
				endSet = 0
				moveX = 0
				moveY = 0
				oldX = 0
				oldY = 0
				newX = 0
				newY = 0
				hitCounter = 5
			Endif	
		Endif
		If direction = 1
			moveX -= (0.1 * speed)
			If moveX < newX
				moveable = 0
				touchedBall = 0
				startSet = 0
				endSet = 0
				moveX = 0
				moveY = 0
				oldX = 0
				oldY = 0
				newX = 0
				newY = 0
				hitCounter = 5
			Endif	
		Endif
	End
	
	Function FindImage:Int(xpos:Float, ypos:Float)
		
		Local x:Int
		For x=1 To AmigaBall.Length-1
			If xpos >= AmigaBall[x].ballX-40 And xpos <= AmigaBall[x].ballX+40 And ypos >= AmigaBall[x].ballY-40 And ypos <= AmigaBall[x].ballY+40
				Return x
			Endif
		Next
	End Function	
	
End

Function Main ()
	New MyTouch
End 


I use array for my image. The reason I have two i that I cant see if I have selected number 0
So I just create a new with number 0 and let it be.

The image can be downloaded from here


skid(Posted 2011) [#2]
You need to dimension the array:

	Global AmigaBall:ball[2]


Are you in debug mode?


Tri|Ga|De(Posted 2011) [#3]
No debug build is not checked in Build options

Is it necessary to set array dimension?
I did try set dimensions but it did not give any difference!


Tri|Ga|De(Posted 2011) [#4]
x-code gives me this in the console:

[Session started at 2011-03-08 22:57:16 +0100.]
AudioStreamBasicDescription:  2 ch,  44100 Hz, 'lpcm' (0x00000C2C) 8.24-bit little-endian signed integer, deinterleaved
Stack dump:
0.	Running pass 'Combine redundant instructions' on function '@gleLLVMVecProjectionTransform3'



Tri|Ga|De(Posted 2011) [#5]
I could really need some help here. I'm planning to make an iOS game so I would like to find out why my code is not working on iOS.


Xaron(Posted 2011) [#6]
Personally I use a map for my resource handler to store images instead of an array. That way I don't have to care about array sizes and so on...


Tri|Ga|De(Posted 2011) [#7]
That does not help me finding out why it craches on iOS and GLFW.


DGuy(Posted 2011) [#8]
Works on HTML5, iOS & GLFW until I click the image twice (old & new positions are the same ?) at which time the following line:
 moveY = ((newY-oldY)/(newX-oldX))*(moveX-oldX)+oldY
Causes 'moveY' to get set to 'nan'

My guess would be a division-by-zero. Check your logic.


Tri|Ga|De(Posted 2011) [#9]
I wil check them. But in my system I do not the change to click before it terminates.

But maybe the nan appear in the start..

[edit]Yes thats it[/edit]