SDL, XP, and problems with my tetris game!

Started by
6 comments, last by Cubed3 18 years ago
Ok so ive tried to port my SDL Mac OS X Tetris game to xp. Now most thing swork correctly, ie the splash screen and music play. However there seems to be something going on in the code somewhere thats messing things up... I have no clue where since im stuck on dev C++ on this computer. If someone could help me troubleshoot my code, it would be much appreciated. Requires SDL and SDL_mixer http://www40.brinkster.com/cub3d/FallingBlockscode.zip Thanks!
Advertisement
you can't expect people to aimlessly debug your code.

pinpoint the problem first.

Learn to make games with my SDL 2 Tutorials

Ive gone through it so many times =( Unfortunatley Dev C++ isn't very helpful for debugging. The one thing that I believe is causing the error is when I create a new Piece object. But I don't know how or why. Ive been going through the code for hours and I can't find anything wrong...

The code compiles and runs perfectly on Mac OS X...
Oh yay, free code [grin]

Anyways, here's a few tips after looking though your code.

1. Go to your void LoadBlocks(void). You are suffering from copy-paste syndrom™. Carefully read over all of your if statments.

2. Go to your Gamefield::Gamefield(void) function. In your second loop, you have:
for(int j = 0; j < MAPWIDTH; j++)	Map[MAPHEIGHT+1][j] = 1;

Now, if you have an array that is declared as Map[MAPHEIGHT][MAPWIDTH], what are the valid indices for that array? Look at what you are doing carefully. The reason you are crashing is because you are just wrecking havok on your computer's memory tables. The fact that it works fine on your other comp is kinda scary [wink]

After you make that second fix, since the first was just error checking code, your game should run without crashing, it did for me. You still have a lot of work to do debugging wise and stuff (saw a few logical bugs), but hopefully that should get you started so you can at least run the program and debug.

Might I reccomend the Visual Studio C++ Express Edition + Platform SDK (ignore that it says 2003, it's the latest). It comes with the VS debugger that will definitly help you out for your future debugging needs [smile] Good luck!
Thanks! That is awfully wierd though with this part of the code
for(int j = 0; j < MAPWIDTH; j++)
Map[MAPHEIGHT+1][j] = 1;

It's wierd because in the class decleratio for Map I do
int Map[MAPHEIGHT+1][MAPWIDTH+1];

:-/ Wierd that would cause the issue.


And yah I noticed the copy/paste syndrome :D Thanks.

Well it all works now, I didn't see any of these other so called logic bugs though :-P Thanks for the help!
The problem is that int Map[MAP_HIEGHT+1] creates an array with vertices of values 0 through MAP_HEIGHT, not 1 thorugh MAP_HEIGHT +1. So when you access MAP_HEIGHT+1, you get one over the maximum.

Eg:

int array[3];

array[0]=0;
array[1]=1;
array[2]=2;//The array only goes up to 3-1, your array would only go up to MAP_HEIGHT+1-1
array[3]=4;<- this would cause a crash, its the 4th element, and it only has 3 of them.
Doh! I can't believe I forgot that.... Ohh well. And yah Drew I did notice a bunch of logical bugs from that and other things :/ Fixed though fixed Fixed Fixed!!!

And in the end there were FallingBlocks
http://www40.brinkster.com/cub3d/

[Edited by - Cubed3 on April 16, 2006 9:54:03 AM]
Doh! double post...

This topic is closed to new replies.

Advertisement