Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are not allowed to catch a <a href="http://msdn.microsoft.com/en-us/library/system.stackoverflowexception.aspx" rel="nofollow"><code>StackOverflowException</code></a> by design:</p> <blockquote> <blockquote> <p>Starting with the .NET Framework version 2.0, a <code>StackOverflowException</code> object cannot be caught by a try-catch block and the corresponding process is terminated by default. Consequently, users are advised to write their code to detect and prevent a stack overflow. For example, if your application depends on recursion, use a counter or a state condition to terminate the recursive loop. </p> </blockquote> </blockquote> <p>I’m sure there are more efficient ways of achieving this. However, to start you off, you can convert your recursion to an iteration by reifying the call stack as a <code>Stack&lt;T&gt;</code>:</p> <pre><code>private void fill(int xInitial, int yInitial, Color border, Color c) { var remaining = new Stack&lt;Tuple&lt;int, int&gt;&gt;(); remaining.Push(Tuple.Create(xInitial, yInitial)); while (remaining.Any()) { var next = remaining.Pop(); int x = next.Item1; int y = next.Item2; Color PointedColor = GetPixel(panel1, x, y); if (PointedColor.R != border.R &amp;&amp; PointedColor.G != border.G &amp;&amp; PointedColor.B != border.B &amp;&amp; PointedColor.R != c.R &amp;&amp; PointedColor.G != c.G &amp;&amp; PointedColor.B != c.B &amp;&amp; x &gt;= 0 &amp;&amp; x &lt; panel1.Size.Width &amp;&amp; y &gt;= 0 &amp;&amp; y &lt; panel1.Size.Height) { SetPixel(panel1, x, y, c); remaining.Push(Tuple.Create(x - 1, y)); remaining.Push(Tuple.Create(x + 1, y)); remaining.Push(Tuple.Create(x, y - 1)); remaining.Push(Tuple.Create(x, y + 1)); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload