Hi, I'm working on a drawing program (in DOS). One of the tools is a colour filler (works the same as in Paint). This works perfectly, however when I exit the program the computer locks up TOTALLY, Ctrl Alt Delete doesn't work. If I remove the filler-code (shown below) it works fine, so the error must be in this code. DrawFill() is the function you run.
The code is pretty large (~3500 lines) so I won't post it all. Here are some quick info on what everything is:
The "picture matrix", where the data is stored.
A temporary matrix, remembers which tiles have been checked (to avoid multiple checks of a tile).
One picture actually contains several pictures. You reach the data of the current picture you're working on via FillOffset.
Holds the current selected colour.
The weird thing is that it seems to work alright (it does what it's supposed to). I've also triple checked that the allocated data gets deallocated. Do you have any idea whats wrong?
//*** Recursive Fill Check ***
void FillCheck(int Xpos, int Ypos, unsigned char Colour)
//Proceed only if this tile hasn't been checked (and if the colour is right)
if(TempToolData[(Ypos*BoardWidth)+Xpos] != 1 &&
BoardData[(Ypos*BoardWidth)+Xpos+FillOffset] == Colour)
BoardData[(Ypos*BoardWidth)+Xpos+FillOffset = CurrentColour;
//Mark that this tile has been checked
TempToolData[(Ypos*BoardWidth)+Xpos] = 1;
//Check more (if within boundries)
if(Xpos < (BoardWidth-1)) FillCheck(Xpos+1, Ypos, Colour);
if(Xpos > 0) FillCheck(Xpos-1, Ypos, Colour);
if(Ypos < (BoardHeight-1)) FillCheck(Xpos, Ypos+1, Colour);
if(Ypos > 0) FillCheck(Xpos, Ypos-1, Colour);
//*** Fills An Area ***
void DrawFill(int Xpos, int Ypos)
//Offset to the drawing board
FillOffset = (CurrentNumber*BoardWidth*BoardHeight);
//Get the colour that should be overwritten
unsigned char TempColour = BoardData[(Ypos*BoardWidth +Xpos+FillOffset];
//Nullify temporary data
memset(TempToolData, 0, (BoardWidth*BoardHeight));
//Don't do anything if it is the same colour
if(TempColour != CurrentColour) FillCheck(Xpos, Ypos, TempColour);