Note that there are some explanatory texts on larger screens.

plurals
  1. POFlood fill algorithm memory leak
    primarykey
    data
    text
    <p>I've got a memory leak somewhere. I've searched it over so many times, and it looks solid to me. I just.. can't... find it... Ok, background. This is a stack driven flood fill, and this bit of code is the only spot where I add something to the stack. There is more code, so if no one can find a memory leak, I'll post some more of it.</p> <p>Here's the strangest part about this. The code works fine with just one color + line art (pictexture), but when using more than one color and using the fill bucket, I get those weird memory leaks.</p> <pre><code> //descend to the floor while(true) { if(++iterator &gt; total) { Debug.Log("broke in the stupid down loop..."); break; } //if we hit line art or a color we're not changing, break out of the loop if(PicTexture.GetPixel((int)coords.x, (int)coords.y).a &gt; .5f || MyTexture.GetPixel((int)coords.x, (int)coords.y) != ColorToChange || coords.y &lt; 0) { break; } //if we're looking right and find an open spot in our texture if(reach.right &amp;&amp; MyTexture.GetPixel((int)coords.x + 1, (int)coords.y) == ColorToChange &amp;&amp; PicTexture.GetPixel((int)coords.x + 1, (int)coords.y).a &lt; .5f) { reach.right = false; //search it and stop looking right if(!search.Contains(new Vector2((int)coords.x + 1, (int)coords.y))) search.Push(new Vector2((int)coords.x + 1, (int)coords.y)); } else { if(MyTexture.GetPixel((int)coords.x + 1, (int)coords.y) != ColorToChange || PicTexture.GetPixel((int)coords.x + 1, (int)coords.y).a &gt;= .5f) //if theres a wall and we're not looking right reach.right = true; //look for an opening to the rightq } //same thing for left if(reach.left &amp;&amp; MyTexture.GetPixel((int)coords.x - 1, (int)coords.y) == ColorToChange &amp;&amp; PicTexture.GetPixel((int)coords.x - 1, (int)coords.y).a &lt; .5f) { reach.left = false; if(!search.Contains(new Vector2((int)coords.x - 1, (int)coords.y))) search.Push(new Vector2((int)coords.x - 1, (int)coords.y)); } else { if(MyTexture.GetPixel((int)coords.x - 1, (int)coords.y) != ColorToChange || PicTexture.GetPixel((int)coords.x - 1, (int)coords.y).a &gt;= .5f) reach.left = true; } MyTexture.SetPixel((int)coords.x, (int)coords.y, BrushColor); coords.y--; } </code></pre> <p>edit: I just realized I forgot to mention the weirdest part. This code works just fine until I use colors other than the starting color (blue). Once I change colors, even if it's back to blue, it still breaks.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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