Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stack overflow in Colobot
#1
Hi. I was trying my new way to write programs i colobot, but it made me pretty fast face stackoverflow. I decided to write program like this:

Code:
public void object::smartGrab(point p)
{
    goto(p);
    grab();
}
Then do stack of overloading functions.
Code:
public void object::smartGrab(object o)
{
    smartGrab(o.position);
}
public void object::smartGrab(int cat)
{
    smartGrab(radar(cat));
}
And then i use my smartGrab(TitaniumOre); in my collectTitanium function, and then i use my collectTitanium in smartBuild function if there is no titanium, and then i use my smartBuild function in makeBot function if there is no BotFactory, and so on.
I found this way of programming super comfy, but it made me hit stackoverflow realy fast (like on 10th nested function). Is my way of programming bad or CBot have very small stack size? How i should deal with this problem?  Confused
#2
I'm pretty sure the limit is about 1000 stack frames (but do keep in note that there are multiple internal stack frames per function call). Are you sure that your functions do indeed get called as expected and you are not running into some other bug that causes the recursion to loop infinitely? If you still think there is something wrong with the stack limit, try to reproduce this issue on a smaller program so we can test it easier.

Just looked into the code to confirm, I was correct with the stack limit - https://github.com/colobot/colobot/blob/...ines.h#L23
#3
I rewited my program and now is ok. I probably messed up and made recursion somewere. btw. Its good to know where it is set in game code. Thanks.


Forum Jump:


Users browsing this thread: 4 Guest(s)