C
C#3mo ago
Gamer1234556

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
mtreit
mtreit3mo ago
Stack overflow is always a danger when you use recursion in C#, how deep is the recursion?
Gamer1234556
Gamer12345563mo ago
Uhhhhhh I am not exactly sure. I designed it that it paints whenever the color is empty and pivots whenever it hits a wall.
mtreit
mtreit3mo ago
Look at how deep the call stack is when you hit the StackOverflow
Gamer1234556
Gamer12345563mo ago
Yeah it kind of goes infinitely
mtreit
mtreit3mo ago
If you have 800x600 = 480000 pixels that seems like a lot of potential recursion.
Gamer1234556
Gamer12345563mo ago
Yeah for sure
mtreit
mtreit3mo ago
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.
Gamer1234556
Gamer12345563mo ago
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
mtreit
mtreit3mo ago
Do you have to use such a large grid?
Gamer1234556
Gamer12345563mo ago
Hmm let me check my Assignment requirements
mtreit
mtreit3mo ago
If you want the complete bodge solution you can try to run your flood fill code on a separate thread with increased stack space.
Gamer1234556
Gamer12345563mo ago
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.
mtreit
mtreit3mo ago
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.