Out Of Stack Space and one other question...

NeverDie
02-06-2002, 06:34 PM
I am experimenting with creating a space-fighter type game and have surprised myself with how I didnt have too much trouble, but I have 2 problems.

1. If the program runs for a few minutes (not even that long really...) it crashes and gives me a "Out of Stack Space" error, the debugger highlights the GameLoop recursion in the main loop for the game (which needs to be there...). Is there any way to clear the stack (whatever the stack is...)? or some other way to get around this?

2. The other problem is the delay in the change of direction. It takes about half a second before the changes start to take effect, but it would be much better if this was quicker...

Any suggestions for either/both of these? thanks.

NeverDie
02-06-2002, 06:36 PM
figured I should probably attach it, hehe.

Spike
02-06-2002, 06:37 PM
edit...nevermind ;)

It would probably be better if you posted the code corresponding to the problem. That would help us figure out what the problem is.

Squirm
02-06-2002, 06:43 PM
Your problem is called recursion. Look here:

Private Sub GameLoop()
Form1.Cls
For i = 0 To maxstars
Star(i).y = Star(i).y + UpDownMovement
If Star(i).x > Form1.Width Then Star(i).x = 1
If Star(i).x < 1 Then Star(i).x = Form1.Width

Star(i).x = Star(i).x + LeftRightMovement
If Star(i).y > Form1.Height Then Star(i).y = 1
If Star(i).y < 1 Then Star(i).y = Form1.Height

Form1.PSet (Star(i).x, Star(i).y), RGB(255, 255, 255)
Next i

DoEvents
GameLoop
End Sub

Now, the offending line is at the end of this procedure when it calls itself again. Each time a function call is made it adds to the stack. It only removes from the stack once it gets to End Sub. However, in your program this never happens.

This is more like what you want:

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Randomize
For i = 0 To maxstars
Star(i).x = Rnd * Form1.Width
Star(i).y = Rnd * Form1.Height
Form1.PSet (Star(i).x, Star(i).y), RGB(255, 255, 255)
Next i

Do
GameLoop
Loop
End Sub

Private Sub GameLoop()
Form1.Cls
For i = 0 To maxstars
Star(i).y = Star(i).y + UpDownMovement
If Star(i).x > Form1.Width Then Star(i).x = 1
If Star(i).x < 1 Then Star(i).x = Form1.Width

Star(i).x = Star(i).x + LeftRightMovement
If Star(i).y > Form1.Height Then Star(i).y = 1
If Star(i).y < 1 Then Star(i).y = Form1.Height

Form1.PSet (Star(i).x, Star(i).y), RGB(255, 255, 255)
Next i

DoEvents
End Sub

:)

NeverDie
02-06-2002, 06:46 PM
yay, that worked, thanx.

any suggestions for my other problem?

Teric
02-07-2002, 10:05 AM
Could you post the whole game (i.e. vbp file, frm files, frx files) so that we can take a look at it? That will help to solve your turning delay problem.

NeverDie
02-07-2002, 02:09 PM
if only there were more :)
this is just practice for a future game, so far thats the only file I have.

NeverDie
02-07-2002, 02:14 PM
Hmm, I seem to have found the problem. The keyboard settings for repeat rate are causing the change of direction to happen only when the repeat kicks in. Is there any way to bypass this?

Banjo
02-07-2002, 05:12 PM
Keep a set of global boolean flags to indicate whether a key is up or down and just use the KeyUp and KeyDown events set these booleans.
So rather than driving your game directly from the events, use the gameloop to handle movement and have it check the boolean flags to decide which direction to move in.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum