Why am I getting a Stack Overflow Exception?

First I wanted to mention like the thread a couple of months ago that I also find this forum to be very helpful and lots of people willing to help the XOJO users community, indeed very refreshing. I haven’t been on here a lot but do find lots of informative (albeit sometimes opinionated :slight_smile: ) topics and I usually post something when I’m stuck. When I get a little more experience with using the XOJO IDE then I hope to become more of a contributor.

I have been working away on my game and am getting a Stack OverFlow Exception when I try to run in a Quick Play Mode. There are no methods calling themselves and there are no DoEvents in the program flow. However, I suppose it could be considered recursive in that it is repeatedly calling some of the same methods numerous times, triggered by a method called both from the Quick Play mode and also when a push button is clicked. Both the push button and this Quick Play mode are calling the same method and theoretically executing the same code, the only difference is that Quick Play mode is repeating the same program flow (a series of methods) until a certain condition is met, and if it isn’t in Quick Play mode the same program flow is only executed once from the Action event of the button. I don’t have any issues when the flow runs only once from the push button event.

I could post some of the code here but it is several methods and would be fairly lengthy. I am hoping this makes sense and someone may have a suggestion as to what could be doing this. This program was running on VB6 and I am using a similar concept with XOJO, actually porting a good chunk of the code. All of my methods have either an Exit or a Return depending on what they do, and as I mentioned there are no DoEvents in this flow. It fails on both Windows and the Mac but seems to fail sooner on the Mac, perhaps because it uses a smaller stack. Since it isn’t an issue from the push button event seems to suggest that the stack is starting anew from the event, but just keeps growing when doing the Quick Play mode. It would be fine if it could do the same thing with Quick Play Mode once it starts a new iteration of the program flow, as I don’t care about what happened from the previous iteration of the flow.

I hope this makes sense … thanks…

Richard

Turn on Break On Exception, then wait for the error to occur. When it does, you will drop into the debugger and there will be a pulldown menu with the list of methods that got you to the current one. You can work your way up that menu and see where each recursion takes places. I think the problem will become quickly evident.

Thanks, I did have the Break On Exception turned on (Lord knows I need that), but I wasn’t looking closely enough at was in the stack to recognize what was going on. The exception was because of a recursive call to a method, where the last method of the flow was calling the first method of the flow for the next iteration of the flow. This is something I was getting away with in VB6 but I guess not anymore. I changed it to use a Do While loop that manages when it’s time to call the first method for a new iteration of the flow, and also had to modify the last method to stop calling the first method. Those steps, actually quite simple, resolved my Stack Overflow issue.

I don’t know what to think about this was working for me on VB6 but not from XOJO as I ported quite a bit of that code. But maybe VB6 was doing a little too much handholding. I look at it now and am thinking this probably should not have worked in VB6.

The default stack size in Xojo is somewhat shallow. You can increase it by using a Thread. Recursion is not necessarily bad, even as you described it.

I have noticed this as i’ve learned Xojo; its much more strict with following convention and “good” programming practices than VB6 was. I suppose its a good thing I already started follow many of them even in VB, otherwise I would be in even more trouble learning Xojo. :slight_smile: