StackOverflow Error using GDIDrawer
Sorry if you seen this post already, but I don't want this to be buried and it seems like I didn't get enough help in the other channels.
So I have been trying to make a FloodFill Winforms Applications that colors a section of a canvas using Recursion. It is a winforms project with three buttons, "Generate" (which generates a series of random blocks), "Fill Color" (which selects the color for the fill recursion algorithm) and the "Fill" that basically does the recursion with the color and initiates whenever the left mouse button is pressed on the Canvas.
However, it seems like when I have been trying to debug my code, I have been facing a Stack Overflow Error. I found this Stack Overflow error specically in the Fill_Color() recursion method and have been trying everything to fix this, yet to no avail. I have my code linked in the pastebin below. Can someone help me?
https://paste.mod.gg/hprjueaagced/0
BlazeBin - hprjueaagced
A tool for sharing your source code with the world!
13 Replies
Stack overflow is always a danger when you use recursion in C#, how deep is the recursion?
Uhhhhhh I am not exactly sure. I designed it that it paints whenever the color is empty and pivots whenever it hits a wall.
Look at how deep the call stack is when you hit the StackOverflow
Yeah it kind of goes infinitely
If you have 800x600 = 480000 pixels that seems like a lot of potential recursion.
Yeah for sure
There is only 1.5 MiB of stack space.
Are you trying to do it recursively as a learning exercise? Because recursion here seems like a bad idea.
I had a Scale to reduce the Stack Space
Yeah I have to use recursion here
According to an assignment
It's not ideal but I don't have a choice in this
Do you have to use such a large grid?
Hmm let me check my Assignment requirements
If you want the complete bodge solution you can try to run your flood fill code on a separate thread with increased stack space.
It said that you need to set the Scale to 10 such that each pixel drawn is a square that is 10x10 pixels in size.
This probably isn’t answering you question, but with this info I think this might answer your question: 80x60.
I don't do graphics programming of any kind, but how big is your actual color array? Is it the original size or the scaled size?
It probably needs to be the scaled size.