Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / What causes a Stack Overflow Error?

Author
Message
gearce
18
Years of Service
User Offline
Joined: 18th Dec 2006
Location: ex SCOTLAND, now MELBOURNE, Australia
Posted: 11th Apr 2008 10:27 Edited at: 11th Apr 2008 10:50
Hi there!

What causes a Stack Overflow Error.

I have a puzzle programme where it works once ...... maybe twice or thrice then I get a message:

Runtime error at line 668. Stack Overflow Error.

The lines in question in my programme are

665 rem Until mouse is clicked
666 do
667 mx=mousex():my=mousey():mc=mouseclick()
668 if mc=1 then gosub checkregion:return
669 loop

Is this enough information to work on? I don't want to reveal too much as my programme is a work in progress.

Any help would be much appreciated.

============ EDIT ============

OK. Found something from a previous post


Quote: "Posted: 27th Apr 2004 00:17

I think it is the way your program runs. It is bad to goto a sub then goto another sub from in that sub. It keeps pilling stuff on the stack."


but I would be interested to hear from others.

Thanks!

gearce
(GRC)

LANG MEY YER LUM REEK

My mother's menu consisted of two choices: take it or leave it.
LBFN
18
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 11th Apr 2008 12:53
If your 'checkregion' subroutine calls the above listed rotuine, you will overflow the stack. Make sure that they do not call one another. You could code it slightly differently:



LBFN
Bluestar4
19
Years of Service
User Offline
Joined: 19th Dec 2005
Location: USA
Posted: 12th Apr 2008 08:49
Interesting......I've never encountered a stack overflow error in DBC.
1. I suggest that you copy your sub routine(s) into the main part of the program and place breaks at every other line until you find the exact portion of your code where it crashes.
in view that dbc doesn't have trace debugging I think you will find that this will be the best solution to find exactly where the bug is -
2. REcursion - CAREfully check your program for recurssion ! whether its a function or a sub , make sure that your program at run time breaks out of each and every one and goes back to its proper place rather than repeatably using resources !

Hummanoid Typhoon
19
Years of Service
User Offline
Joined: 4th Aug 2005
Location: Middle of nowhere
Posted: 12th Apr 2008 16:02
Does it get stuck within a never ending sub?

Never got one in DBC but in c# you get stack overflows if you perform lots of sequential operations within the main forms thread without letting it refresh.

gearce
18
Years of Service
User Offline
Joined: 18th Dec 2006
Location: ex SCOTLAND, now MELBOURNE, Australia
Posted: 13th Apr 2008 04:23
Thanks everyone for your replies.

To LBFN

Your help with a query in the TGPF forums solved this problem. Thank you!

gearce
(GRC)

LANG MEY YER LUM REEK

My mother's menu consisted of two choices: take it or leave it.
LBFN
18
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 13th Apr 2008 05:17
You're welcome...glad to help.

LB

Login to post a reply

Server time is: 2025-06-07 17:09:41
Your offset time is: 2025-06-07 17:09:41