Jump to content
  • Advertisement
Sign in to follow this  
Ezbez

Problem with recursion with c++

This topic is 4892 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Quote:
Original post by Ezbez
until I started to get strange fatal crashes.


Forgot to ask, what were the actual errors you got? That would be helpful. Also, once you have the error codes, try Googling them, you might get lucky and find not only the error but a suggested solution. I've done that a few times.

Share this post


Link to post
Share on other sites
Advertisement
As said above, I get segmentation faults. This doesn't exactly seem like recursion, but I do make sure that its within the correct boundries, so I'm really sure how I could get a segmentation fault.

Oh, since tileMap is actually 100 by 100, the -100 or whatever is actually just moving one square up(the origin is at the top of the screen).

Share this post


Link to post
Share on other sites
Quote:
Original post by Ezbez
The error message that I get is actually a segmentation fault at the first.

I would test the validity of the tileMap pointer in the erroring sections. Does your IDE allow setting breakpoints? I didn't notice which one you were using, although I also missed where you explained exactly what the error was ;) .

Share this post


Link to post
Share on other sites
I do test the validity of it. I'm not really familiar with my IDE's debugger(I'm using Dev-C++), but I believe it does allow breakpoints.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ezbez
As said above, I get segmentation faults. This doesn't exactly seem like recursion, but I do make sure that its within the correct boundries, so I'm really sure how I could get a segmentation fault.


You get a segmentation fault if you try to access invalid memory locations.
In your case, overflowing the stack (with a hugh function call depth) can cause a segmentation fault.

In fact, I think Trap is right. Even though you stay between 0 and 9999 you could loop forever.

I would suggest you do a printf("(%d, %d)\n", num, corner) at the beginning of the function and see what is being printed. I am pretty sure you will find repeated pairs there.

Share this post


Link to post
Share on other sites
When I was filling my tile map (128 x 128) I got the stack overflow aswell, but when I made the tile map 64 x 64 in size, things started to work again.
You can try to reduce the size of the tile map, and see if that helps ^^
If nothing else, it will give you a hint about what is wrong

Just a thought

Share this post


Link to post
Share on other sites
What on earth are all these bizarre numbers? I assume you intend to do something or other with a 2-dimensional array?

Try to explain what exactly this is supposed to do overall, and I might be able to help make more sense of it.

Share this post


Link to post
Share on other sites
OOps, I geuss I never did post one post that I was writing. For the 'weird numbers', yes that is actually a 2D arry, so the -100 is actually just moving one 'up'.

I tired the outputs, and got no repeating numbers, but it did have approximately 200 entries before crashing. So I'm thinking that I'm not stopping the recursion when it needs to be.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Zahlman
Unless you have a heavy resource allocation or a very large problem size, stack overflow from recursion usually results from the recursions being 'infinite' (unbounded) -


It isn't recursion if it's infinite -- it's a bug.

The definition of recursion requires a terminating condition to end the algorithm. If the program does not terminate, it is neither recursive nor an algorithm by definition.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!