Out of Stack Space

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
DaveUnit
Veteran
Posts: 72
Joined: Sat Oct 29, 2005 10:07 am

Out of Stack Space

Post by DaveUnit »

If anyone would be so kind, could someone elaborate on the Out of Stack Space error? I'm aware of what the stack is sort of but I'm afraid I don't know well enough to totally understand what this error means. Any help would be appreciated. I just want my lil' game to work properly, and not... ya know... bad.
Thanks again, you guys are great.
Dave.
User avatar
The Awakened
Veteran
Posts: 144
Joined: Sun Aug 07, 2005 1:51 am

Post by The Awakened »

Basically, the stack is a memory structure that you can push variables onto and pop them off. You'd have to get into assembly to really understand how the stack works.

To fix your error, put this somewhere at the beginning of your program:

Code: Select all


CLEAR ,,5000

Good luck man! :D
"Sorry for beating you up with a baseball bat Julian, but I DID think that you were a samsquanch."
DaveUnit
Veteran
Posts: 72
Joined: Sat Oct 29, 2005 10:07 am

Post by DaveUnit »

Hey, thanks alot! I'll try that out when I get home (I'm currently in my computer tech class).
Did I mention you guys are great? :P
Thanks yet again,
Dave.
User avatar
matt2jones
Veteran
Posts: 80
Joined: Sat Feb 19, 2005 8:29 am
Location: elsewhere
Contact:

Post by matt2jones »

Ehh, It's probably more likely that you've got an out of stack error because you've called too many subs withing subs... (If your a begginner)

Post up the code here and I'll explain it to you.

matt
Do not mistake Apathy for feeling Content.

http://www.disjointed.cjb.net - Short Storys
http://matt2jones.deviantart.com - Random Art
http://www.freewebs.com/matt2jones - WebComic
DaveUnit
Veteran
Posts: 72
Joined: Sat Oct 29, 2005 10:07 am

Post by DaveUnit »

Actually Matt, i tried what the Awakened said and the bug I had was no longer present. But what you posted about too many subs within subs makes me feel like retooling the program a bit. So, I think I'll do that today so as to not create more stack related problems.
Thanks Matt.
Dave
User avatar
ShadowWolf
Veteran
Posts: 56
Joined: Thu Mar 04, 2004 1:32 pm
Contact:

Post by ShadowWolf »

if your using gosub ick then you might run into a stack error there.

function / subs you really shouldn't run into a stack error unless you have some kind of recursion error. i.e. calling a the same function in a loop with in that function in which it can never be resolved or runs out of stack space before the recursion can resolve it self.
DaveUnit
Veteran
Posts: 72
Joined: Sat Oct 29, 2005 10:07 am

Post by DaveUnit »

Thanks Shadow wolf. I'm definitely not using gosub, so I guess I should be fine now. Now on to fixing some other bugs! I got one that's been stumping me for awhile now, but I'm determined to figure it out. I'm just trying to make a program that I can be proud of so I'd like to figure out as much as I can on my own rather than asking for help every time I have a little bug.
Thanks again to all you guys that helped me, I really do appreciate it.
Dave
User avatar
matt2jones
Veteran
Posts: 80
Joined: Sat Feb 19, 2005 8:29 am
Location: elsewhere
Contact:

Post by matt2jones »

You'll come across an out of stack error if you never return from subs or gosubs... Beginners tend to write code where this happens (just because they're starting).

Eg:

Code: Select all


'My game!!!!

Menue   'Start here

'=-=-=-=-=-=-=-

SUB menue
     'blah
     PRINT "would you like to play?":input A$:if A$ = "n" then end
     Game
END SUB

SUB game
      'blah
      if int(rnd*100)<20 then FIGHT
      'blah
END SUB

SUB fight
       if eHp < 1 then game 'You Won!!!!!
       if Hp < 1 then menue '?ou Died!!!!
END SUB


Running anything structured like that will flood the stack. You can dodge it a little by making sure your stack is fork huge, but it will flood. The point is to try and learn how to structure your sub's utilising the EXIT SUB command....

If your subs are called like that, then you would need to re-jig them...

matt
Do not mistake Apathy for feeling Content.

http://www.disjointed.cjb.net - Short Storys
http://matt2jones.deviantart.com - Random Art
http://www.freewebs.com/matt2jones - WebComic
DaveUnit
Veteran
Posts: 72
Joined: Sat Oct 29, 2005 10:07 am

Post by DaveUnit »

Alrighty then.
Thanks again, Matt.
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

A good way for the beginner to understand Subs is to look at them as if they were boxes. "What goes in must come out"...in other words, if you enter a Sub, you have to eventually exit the Sub. Once you understand how that works, you're good to go. :)
DaveUnit
Veteran
Posts: 72
Joined: Sat Oct 29, 2005 10:07 am

Post by DaveUnit »

Thanks for that little explanation Nekropidius!
I've been re-working the program a bit to fit the "what goes in must come out" theme of subroutines like you said, Nekrophidius.

I'm glad I joined this forum, so much good advice. :D
Well, Seacrest out! :P
Dave
Post Reply