Odd Bug!

Discussion about everything. New games, 3d math, development tips...
Post Reply
JPulham
Posts: 320
Joined: Sat Nov 19, 2005 12:06 pm

Odd Bug!

Post by JPulham »

Hi, I have an odd bug. I started with just the if statments below (not embeded in 'validation if's')
The game is a game where you click a colored block it disappears with the surround in blocks of the same color. However, when I call erase inside this function, it causes an illegal operation :?

Can anyone see anything wrong with this code?

Code: Select all

void Erase(int x, int y, int ex)
{
    int tokill = g_blocks[x][y];
    g_blocks[x][y] = BLOCK_EMPTY;
    //kill the linked ones
    if(((x + 1) <= 9) && (ex != EXCLUDE_LEFT))
    {
        if(g_blocks[x + 1][y] == tokill)
        {
            Erase(x + 1, y,EXCLUDE_LEFT);
        }
    }
    if(((x - 1) >= 0) && (ex != EXCLUDE_RIGHT))
    {
        if(g_blocks[(x - 1)][y] == tokill)
        {
            Erase(x - 1, y,EXCLUDE_RIGHT);
        }
    }
    if(((y + 1) <= 15) && (ex != EXCLUDE_BELOW))
    {
        if(g_blocks[x][(y + 1)] == tokill)
        {
            Erase(x, y + 1,EXCLUDE_BELOW);
        }
    }
    if(((y - 1) >= 0) && (ex != EXCLUDE_ABOVE))
    {
        if(g_blocks[x][(y - 1)] == tokill)
        {
            Erase(x, y - 1,EXCLUDE_ABOVE);
        }
    }
}
pushpork
ErUs
Posts: 165
Joined: Thu Oct 07, 2004 6:13 pm

Post by ErUs »

either step through with a debugger and find the exact line it fails on, or put lots and lots of printf()'s in theres and then see where the problem is :)
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Hmm, I'm not really sure, but one thing makes me curious...
For example this line:

Code: Select all

if(((x + 1) <= 9) && (ex != EXCLUDE_LEFT))
x+1 is the field to the right, isn't it ???
So should it not be like this:

Code: Select all

if(((x + 1) <= 9) && (ex == EXCLUDE_LEFT))
the same for all other comparisons...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
JPulham
Posts: 320
Joined: Sat Nov 19, 2005 12:06 pm

Post by JPulham »

@acki:
I put that code in after it started failing... to try and validate... but it didn't work.

I'll just have to step through, I did try some message boxes but I just thought it was an odd bug and wondered if there was an obvious error only I couldn't see :?
pushpork
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Well, it's not easy to debug a code snippet, since it's a recursive calling function and we don't know about the rest of the code... ;)

If you don't get it on your own, it will be a great help for us to have the whole code (maybe as download) so we can check it !!!

It also can be that the function is flipping between left-right-left-right- and so on (or up-down-up-down), and causing a stack overflow...

Or maybe you should think about another way to delete the blocks... :wink:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
JPulham
Posts: 320
Joined: Sat Nov 19, 2005 12:06 pm

Post by JPulham »

fixed...

Code: Select all

if the block is empty don't bother
I could debug it I just wondered if you could fix it before my friend went home... but it works now.
pushpork
Post Reply