app runs correctly only with debug

BlitzPlus Forums/BlitzPlus Programming/app runs correctly only with debug

Nathan(Posted 2004) [#1]
I have made a small app that only functions correctly with debug enabled. If disable the debug the balmax variable (see code below, that determines the number of particles, is not updated anymore. Any ideas?


While WaitEvent()
	Select EventID()
	Case $101 ; EventID keydown
		Delete_Balls(b.ball)
		t=0
		InitBalls(b.ball,balmax)
	Case $401 ;EventID gadget action
		If EventSource()=button1 Then 		
			balmax=TextAreaText(textfield1)
			Stop
		
		End If
		
	Case $803 ;EventID window close.
		End
	Case $2001	;suspend deze applicatie
		While WaitEvent()<>$2002
		Wend
	Case $4001 ; EventID checks when timer is timed out
		Cls
		Place_Ball(b.ball)
		Move_Ball(b.ball)
		FlipCanvas canvas
		t=t+1
		FlushEvents $4001
	End Select
Wend



Drago(Posted 2004) [#2]
err have you tried commenting out the stop command, and just looking at your code it should work, (without that stop command).


Nathan(Posted 2004) [#3]
Drago, thatīs exactly the problem. When I take the stop comment out and the debug disabled the balmax variable doesnīt get updated anymore and the explosions (the app is a small particle engine), seize to work.
If I put the stop command in again and enable the debug mode everything works fine.


Drago(Posted 2004) [#4]
hmm, well unless I/We can see an example that has the same problem, it is hard to see what is causeing it to do that (since the error might be somewhere else.)

Another thing to note, is that you are do a while loop for waitevent(), you might be better off having it like this.
done=false
while done=false
waitevent()
Select EventID()
...
...
...
end select
Wend


probably wont fix your problem but it is a better thing to do.
it also lets you have the quit code only once (if you need to free stuff) since you can have all events that kill the program after the loop.
done=false
while done=false
waitevent()
Select EventID()
...


Case $803 ;EventID window close.

done=true
...
end select
Wend
end



Nathan(Posted 2004) [#5]
Thanks for the advice regarding the While loop. However as you expected it didnīt solve the problem.
I will post the complete code below so that anyone can try it out.
Global canw
Global canh
Global t
Global balmax

Type Ball
	Field x#,y#
	Field dx#,dy#
	Field size
	Field tt
	Field r,g,b
End Type


window=CreateWindow("Particle Engine",50,50,700,600)
CreateLabel("Number of particles",ClientWidth(window)/2-140,ClientHeight(window)-30,100,20,window)
textfield1=CreateTextArea(ClientWidth(window)/2-25,ClientHeight(window)-30,50,20,window)
button1=CreateButton("Ok",ClientWidth(window)/2+50,ClientHeight(window)-30,20,20,window)

UpdateWindowMenu window ; This MUST be called after creating your menu!
canvas = CreateCanvas (0, 0, ClientWidth (window), 500, window)
SetGadgetLayout canvas, 1, 1, 1, 1 ; Use zero to leave an edge 'unpinned'...

canh=GadgetHeight(canvas)
canw=GadgetWidth(canvas)

; MAKE BUFFER
SetBuffer CanvasBuffer(canvas)
done=False
timer=CreateTimer(25)
t=0 ;globale variabele om na enige tijd bal te verwijderen
balmax=100 ;maximum aantal ballen of particles

InitBalls(b.ball,balmax)

While done=False
	WaitEvent()
	Select EventID()
	Case $101 ; EventID keydown
		Delete_Balls(b.ball)
		t=0
		InitBalls(b.ball,balmax)
	Case $401 ;EventID gadget action
		If EventSource()=button1 Then ;verander het aantal ballen naar de textfield waarde
		;Stop
			;SetStatusText(window,Str(balmax))
			balmax=TextAreaText(textfield1)
			;Stop
		
		End If
		
	Case $803 ;EventID window close.
		done=True
	Case $2001	;suspend deze applicatie
		While WaitEvent()<>$2002
		Wend
	Case $4001 ; EventID checks when timer is timed out
		Cls
		Place_Ball(b.ball)
		Move_Ball(b.ball)
		FlipCanvas canvas
		t=t+1
		FlushEvents $4001
	End Select
Wend
End


;**************************************** FUNCTIONS *****************************************



Function Create_Ball(b.ball,x#,y#,dx#,dy#,size,tt,r,g,bb)
	b.ball=New Ball
	b\x=x#
	b\y=y#
	b\dx=dx#
	b\dy=dy#
	b\size=size
	b\tt=tt
	b\r=r
	b\g=g
	b\b=bb
End Function

Function InitBalls(b.ball,balmax)
	For i=1 To balmax
		x#=canw/2+Rnd(-5,5)
		y#=canh/2+Rnd(-5,5)
		dx#=Rnd(-5,5)
		dy#=Rnd(-5,5)
		size=Rnd(2,10)
		tt=Rnd(50,200)
		Create_Ball(b.ball,x#,y#,dx#,dy#,size,tt,Rnd(200,255),Rnd(150,200),Rnd(0,10))
	Next
End Function


Function Place_Ball(b.ball)
	For b.ball=Each Ball
		Color b\r,b\g,0
		Oval b\x,b\y,b\size,b\size,1
	Next
End Function

Function Move_Ball(b.ball)
	For b.ball=Each Ball
		b\x=b\x+b\dx
		b\y=b\y+b\dy
		If b\tt<t Then
			Delete b.ball
		End If
	Next
End Function

Function Delete_Balls(b.ball)
	For b.ball=Each Ball
		Delete b
	Next
End Function
		



Kev(Posted 2004) [#6]
sightly modifyed.

[CODE]
Global canw
Global canh
Global t
Global balmax


Type Ball
Field x#,y#
Field dx#,dy#
Field size
Field tt
Field r,g,b
End Type


window=CreateWindow("Particle Engine",50,50,700,600)
CreateLabel("Number of particles",ClientWidth(window)/2-140,ClientHeight(window)-30,100,20,window)
textfield1=CreateTextArea(ClientWidth(window)/2-25,ClientHeight(window)-30,50,20,window)
button1=CreateButton("Ok",ClientWidth(window)/2+50,ClientHeight(window)-30,20,20,window)

UpdateWindowMenu window ; This MUST be called after creating your menu!
canvas = CreateCanvas (0, 0, ClientWidth (window), 500, window)
SetGadgetLayout canvas, 1, 1, 1, 1 ; Use zero to leave an edge 'unpinned'...

canh=GadgetHeight(canvas)
canw=GadgetWidth(canvas)

; MAKE BUFFER
SetBuffer CanvasBuffer(canvas)
done=False
timer=CreateTimer(25)
t=0 ;globale variabele om na enige tijd bal te verwijderen
balmax=100 ;maximum aantal ballen of particles

InitBalls(b.ball,balmax)

While done=False
event = WaitEvent()
Select EventID()
Case $101 ; EventID keydown
Delete_Balls(b.ball)

InitBalls(b.ball,balmax)
Case $401 ;EventID gadget action

Select EventSource()

Case button1
Delete_Balls(b.ball)
balmax=TextAreaText(textfield1)
InitBalls(b.ball,balmax)

End Select

Case $803 ;EventID window close.
done=True
Case $2001 ;suspend deze applicatie
While WaitEvent()<>$2002
Wend
Case $4001 ; EventID checks when timer is timed out

Cls
Place_Ball(b.ball)
Move_Ball(b.ball)
FlipCanvas canvas
t=t+1
FlushEvents $4001

End Select
Wend
End


;**************************************** FUNCTIONS *****************************************



Function Create_Ball(b.ball,x#,y#,dx#,dy#,size,tt,r,g,bb)
b.ball=New Ball
b\x=x#
b\y=y#
b\dx=dx#
b\dy=dy#
b\size=size
b\tt=tt
b\r=r
b\g=g
b\b=bb
End Function

Function InitBalls(b.ball,balmax)
For i=1 To balmax
x#=canw/2+Rnd(-5,5)
y#=canh/2+Rnd(-5,5)
dx#=Rnd(-5,5)
dy#=Rnd(-5,5)
size=Rnd(2,10)
tt=Rnd(50,200)
Create_Ball(b.ball,x#,y#,dx#,dy#,size,tt,Rnd(200,255),Rnd(150,200),Rnd(0,10))
Next
End Function


Function Place_Ball(b.ball)
For b.ball=Each Ball
Color b\r,b\g,0
Oval b\x,b\y,b\size,b\size,1
Next
End Function

Function Move_Ball(b.ball)
For b.ball=Each Ball
b\x=b\x+b\dx
b\y=b\y+b\dy
If b\tt<tt Then
Delete b.ball
End If
Next
End Function

Function Delete_Balls(b.ball)
For b.ball=Each Ball
Delete b.ball
Next
End Function
[/CODE]

works here.

kev


Nathan(Posted 2004) [#7]
Everything works fine now. Thanks for all your help.

Nathan