Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Massive int values?

Author
Message
MPQC
14
Years of Service
User Offline
Joined: 7th Sep 2009
Location:
Posted: 18th Nov 2010 03:25
Hey! Been awhile since I've been here, and I felt like making a Tetris clone, just for fun. So I'm about an hour into it (almost got collision, but I've hit this roadblock and decided not to continue until it's fixed), and I've spent the last hour trying to debug this issue, but it's just not working! Basically, the way the code works is that every second (60 frames), it updates where the players block is. So it'll check for collision, update the blocks placing on the screen, etc. Now, every time this happens, it increases the y value by 1, so it moves down 1 block. But, here's where my issue comes in. While debugging it, one of my x values will just shoot up to 16777228, and since that's much too big for an int, it just crashes the program. I have nowhere in the code that should do anything even remotely close to this, but yet it happens. I was wondering if someone could take a look at it and see if there's anything obviously wrong. So here's the code:



And don't mind my global variables please, this is a rush job.

Media required is attached below.

Attachments

Login to view attachments
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 18th Nov 2010 04:17
Quote: "While debugging it, one of my x values will just shoot up to 16777228, and since that's much too big for an int, it just crashes the program."


There's no such thing as a value too big for an int, it will just get truncated and not cause any crash.

The issue is most likely that you're not doing any bounds checking, in your main loop you run UpdateMovement() all the time and the only check you're doing is in CheckBottom() with the line 'if (piece1_y == 20)' which will become 21 in the next loop thus fail the check. This causes you to access an element out of bounds in UpdatePosition() with 'Board[piece1_x][piece1_y] = true;'. If you must use arrays like this then write a function such as: getBoardCell() or similar, that first checks if the x/y is valid before returning the element.

MPQC
14
Years of Service
User Offline
Joined: 7th Sep 2009
Location:
Posted: 18th Nov 2010 04:21
When it reaches the bottom, it swaps to a new piece, and the coordinates get reset. (Back to whatever the x/y coordinates are of the piece it's going to chose.)
MPQC
14
Years of Service
User Offline
Joined: 7th Sep 2009
Location:
Posted: 18th Nov 2010 05:22
Actually, it makes sense what you said. I'll check it out in a bit, and stick a check first.
MPQC
14
Years of Service
User Offline
Joined: 7th Sep 2009
Location:
Posted: 19th Nov 2010 16:28
Works great now. Thanks.

Login to post a reply

Server time is: 2024-06-30 10:50:09
Your offset time is: 2024-06-30 10:50:09