|
Post by johnno56 on Jan 27, 2020 15:32:58 GMT -6
Not really a bug, per se, more of a curiosity.... Is it possible that there may be a memory leak associated with FloodFill? Reason: I am converting my sdlbasic sprite editor to RC. When drawing on the main grid, sdlbasic uses the standard paint() command, whereas RC uses FloodFill(). Drawing on the main grid, sdlbasic, paints the cells that the mouse touches... RC, not so much... If more that one cell is filled the program terminates with a 'segmentation fault 139' - if memory (no pun intended) serves correctly then that usually mean an array dimension is too small? In the past, increasing the value by one, usually fixes it... but not this time. I am trying to code a floodfill routine that I can use in the meantime (not working yet... lol) I will attach the current RC listing... Be warned... It's NOT pretty! All needed fonts and images will be included. spredit.zip (220.07 KB) Note: "Load" will use a hard coded image. "New" works but may need more work. "Save" Not coded yet. "Quit" works like a charm. Who knew? lol
|
|
|
Post by n00b on Jan 27, 2020 20:21:10 GMT -6
Hey Johnno, I looked at it and it does appear to be a bug. The bug seems to be triggered only if you try to fill an area with the same color. I am not sure why but you can get around it by tracking the colors that are already in each cell and making sure not to fill it with the same color. I will have this fixed in the next release.
With all that said, there is a number of things you could potentially change to make this more efficient. The first thing is to just use RectFill instead of FloodFill. RectFill is probably atleast 10x faster than FloodFill. Also I noticed you were using GetPixel to get the colors. Instead of using that it would probably be better to store all the color values in an array and then if a certain color is selected you could just set the color based off of what index in the array is associated with that color. This would also greatly improve performance.
|
|
|
Post by johnno56 on Jan 27, 2020 22:25:32 GMT -6
Cool... a minor bug... Not cool that there is a bug... Cool that a bug was found... lol Ha. Dodged a bullet there... lol
Funny you should mention colours in arrays... The original sdl listing had all the colours, and their proper colour names, in arrays. First, I had them all stored in an external file, then inserted into arrays. Then I included them all within the main listing... I pretty much go for what's easiest and went with getPixel() and a mess of 'if...then's'... Your efficiency tip is noted and will put it back to the way it was...
But I still have to use the mouse to select a colour. If I don't use getPixel... Oh now my brain hurts....
I agree with the RectFill, instead of FloodFill, but I couldn't figure out how to do that... I still have no clue... and the original sdl program that I wrote is probably 5 years old... So much for slow learning... lol
In the meantime, do you have a floodfill routine, that can serve as a 'work-a-round'... I have found SO many examples... 4way; 8 way; Recursive; Non-recursive; Scanline... So confused... or even better... a way to get RectFill to work...
Do you think I might be "biting off more that I can chew"?
|
|
|
Post by johnno56 on Jan 28, 2020 1:50:50 GMT -6
I found a very early prototype of the editor (sdl) which fills the cell using a for x = and a for y = and plots a dot at x,y. The cell is only 20x20 so the "fill" is very quick. But I still have to workout how the program locates the 0,0 coords of the cell by clicking anywhere within the cell... I hope this makes sense. If I can figure it out, then that will solve my "fill" issue, and thereby relieve you of any pressure to correct FloodFill() quickly... I will keep you posted...
|
|
|
Post by johnno56 on Feb 1, 2020 20:55:37 GMT -6
Hey n00b,
I managed to resurrect my Editor prototype and have successfully integrated the "fill" routine. I took your advice and used RectFill(). The program is very buggy (verging on infestation... lol) but the 'draw to screen' runs really well. I will try to post a current version in "Projects" - as soon as I get rid of some of the 'really' annoying bugs...
|
|