BlitzMax app crashes and I don't know why

BlitzMax Forums/BlitzMax Programming/BlitzMax app crashes and I don't know why

Koekelas(Posted 2005) [#1]
My BlitzMax app crashes and I don't know why. The flowing function from my type TPlayer contains the bug.

Function createPlayer:TPlayer()
	
	Local player:TPlayer = New TPlayer
	
	player.x	= MouseX()
	player.y	= MouseY()
	
	Local point1:TPoint	= TPoint.createPoint(player.SIZE / 2, 0)
	Local point2:TPoint	= TPoint.createPoint(player.SIZE, player.SIZE)
	Local point3:TPoint	= TPoint.createPoint(0, player.SIZE)
	
	drawTriangle(point1, point2, point3)
	
	player.image = CreateImage(player.SIZE, player.SIZE)
	
	GrabImage(player.image, 0, 0)
	
	Return player
EndFunction


When I comment out the lines from drawTriangle... to Return it works. Two hours past and still I didn't find the bug.


Thanks, Nicolas.


EOF(Posted 2005) [#2]
Does player.SIZE have a value of 0 by chance?


Koekelas(Posted 2005) [#3]
No, it haze a value of 128.


Nicolas.


klepto2(Posted 2005) [#4]
If it has a value of 128, where is it declared in this function.
I mean something like:

player.size = 128


EOF(Posted 2005) [#5]
klepto,
I guess he sets this during the creation of the TPlayer:
Type TPlayer
 Field size=128
End Type
Is player.image a TImage?
Maybe the bug is in the drawtriangle funtion(?)


Koekelas(Posted 2005) [#6]
That's correct jb, it's a Constant. Yes player.image is a TImage and no drawTriangle works perfect. Maby this helps:

tPoint.bmx
Strict

Framework BRL.GLMax2D
Import BRL.Basic
Import BRL.System

Type TPoint
	
	Field x:Int
	Field y:Int
	
	'** createPoint:TPoint(x:Int, y:Int) **************************************************************
		
		Function createPoint:TPoint(x:Int, y:Int)
			
			Local point:TPoint = New TPoint
			
			point.x	= x
			point.y	= y
			
			Return point
		EndFunction
	'** End createPoint:TPoint(x:Int, y:Int) **********************************************************
EndType

'** drawTriangle(point1:TPoint, point2:TPoint, point3:TPoint) **************************************
	
	Function drawTriangle(point1:TPoint, point2:TPoint, point3:TPoint)
		
		Cls
		
		DrawLine point1.x, point1.y, point2.x, point2.y
		DrawLine point2.x, point2.y, point3.x, point3.y
		DrawLine point3.x, point3.y, point1.x, point1.y
	EndFunction
'** End drawTriangle(point1:TPoint, point2:TPoint, point3:TPoint) **********************************


tPlayer.bmx
Import "tPoint.bmx"

Type TPlayer
	
	Const SIZE:Int = 128
	
	Field x:Int
	Field y:Int
	Field image:TImage
	
	'** createPlayer:TPlayer() ************************************************************************
		
		Function createPlayer:TPlayer()
			
			Local player:TPlayer = New TPlayer
			
			player.x	= MouseX()
			player.y	= MouseY()
			
			Local point1:TPoint	= TPoint.createPoint(player.SIZE / 2, 0)
			Local point2:TPoint	= TPoint.createPoint(player.SIZE, player.SIZE)
			Local point3:TPoint	= TPoint.createPoint(0, player.SIZE)
			
			'>>> drawTriangle(point1, point2, point3)
			'>>>
			'>>> player.image = CreateImage(player.SIZE, player.SIZE)
			'>>>
			'>>> GrabImage(player.image, 0, 0)
			'>>>
			Return player
		EndFunction
	'** End createPlayer:TPlayer() ********************************************************************
	
	'** draw() ****************************************************************************************
		
		Method draw()
			
			DrawImage image, x, y
			
			update()
		EndMethod
	'** End draw() ************************************************************************************
	
	'** update() **************************************************************************************
		
		Method update()
			
			x	= MouseX()
			y	= MouseY()
		EndMethod
	'** End update() **********************************************************************************
EndType



Nicolas.


Koekelas(Posted 2005) [#7]
Would the crashlog be of any use?


Nicolas.


BlitzSupport(Posted 2005) [#8]
What happens if you leave just one of those lines in? For example, does it crash if you just uncomment DrawTriangle?


Koekelas(Posted 2005) [#9]
Yes, when I uncomment the drawTriangle it crashes but I'm certain that's not the problem because it works in other parts of my program.


Nicolas.


BlitzSupport(Posted 2005) [#10]
What happens if you do it the other way around, ie. comment out DrawTriangle and enable the other two lines?

Do you have the debugger on? Do you get any error messages if so?


Perturbatio(Posted 2005) [#11]
Shouldn't this image be created with the DYNAMICIMAGE flag since you're using grabimage?
	player.image = CreateImage(player.SIZE, player.SIZE)



Koekelas(Posted 2005) [#12]
If I'm not mistaking if you create an image whit CreateImage it's always combined whit DYNAMICIMAGE. Anyway I tried it and sadly it doesn't work :(.


Nicolas.


Perturbatio(Posted 2005) [#13]
This works (albeit the triangle doesn't draw properly).



Koekelas(Posted 2005) [#14]
Yes it works. Hmmm strange. What am I doing different?

By the way to get the triangle to draw properly:
Local point1:TPoint	= TPoint.createPoint(player.SIZE / 2, 0)
Local point2:TPoint	= TPoint.createPoint(player.SIZE - 1, player.SIZE - 1)
Local point3:TPoint	= TPoint.createPoint(0, player.SIZE - 1)

But you already knew that ;).


Nicolas.