changing luminosity by rgb values.(my tetris game project)

The Partridge Family were neither partridges nor a family. Discuss.
User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: changing luminosity by rgb values.(my tetris game proje

Post by chili » June 24th, 2012, 3:17 pm

I didn't notice before that you posted the solution. Cool game bro. 8-)

Oh, and I figured out why Release mode wasn't working for you. ;)
Chili

User avatar
viruskiller
Posts: 399
Joined: June 14th, 2012, 5:07 pm

Re: changing luminosity by rgb values.(my tetris game proje

Post by viruskiller » June 24th, 2012, 4:31 pm

may i know why :lol: ?

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: changing luminosity by rgb values.(my tetris game proje

Post by chili » June 25th, 2012, 12:08 am

Let's see if you can work it out on your own. :lol:

I will give you some pointers. First, in consideration of the symptoms, where in your code would you expect the bug (it is a bug) to be?
Chili

User avatar
viruskiller
Posts: 399
Joined: June 14th, 2012, 5:07 pm

Re: changing luminosity by rgb values.(my tetris game proje

Post by viruskiller » June 25th, 2012, 2:27 pm

it could be in many places :lol: ,although i think is where i defined my setsquare state,getsquarestate functions for the x and y values,or because i'm using them mixed in some places... tought about limitation to window mechanics i have in place ,though i find it hard to belive that all 3 of hem faill .

anyway from what i seen i think is happening because the compiller inlines some functions and they mess up other code.

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: changing luminosity by rgb values.(my tetris game proje

Post by chili » June 25th, 2012, 4:11 pm

Incorrect. ;)

It is happening because you wrote code that contains an undefined condition (you have a bug). Don't blame the compiler bro; walk into the bathroom, turn on the light, face the mirror and point straight ahead. :lol:

Now, think about it. The problem is that full lines are not being recognized. Where would be the most logical place to look to find this bug?
Chili

User avatar
viruskiller
Posts: 399
Joined: June 14th, 2012, 5:07 pm

Re: changing luminosity by rgb values.(my tetris game proje

Post by viruskiller » June 25th, 2012, 6:11 pm

what i;ve found is .... WHAT THE !!!!!! !
i just realized my code was working in debug mode with no problems and shape draw function returned true even if it didn't hit anything to say it's true,
also that it returns false in release mode even tough it didn't hit any return false statement.

in the "if statement" that was checking for shape collision with solid blocks i forgot to put a return true statement if it evaluated as true, and only had return false statement if evaluated as false,
this was the original code

Code: Select all

bool Game::DrawShape(int x,int y,int lx,int ly,shape sp,SQRState state)
{
	if(!GameOver()) //chekcking if game is not over...
	
	
	{
      int ymax=ShapeXYpos(x,y,SP,8);    
	  int minX=ShapeXYpos(kx,ky,SP,1);													  //calling ShapeXYpos to get the min x and max x coordinates in relation ship with kx,ky ,shape model and shape facing
	  int maxX=ShapeXYpos(kx,ky,SP,2);													//getting the y value of the bottom most block of current shape;
	  if
		  (CollisionCheck(x,y,SP)&&ymax<18)											//square check statement,cheks if the shape did not hit any other shape or the bottom of square table,i have left and right movement cheks so it cannot tough other shapes from the side
		{
			SetSquareState(ShapeXYpos(kx,ky,SP,1),ShapeXYpos(kx,ky,SP,5),state);		//setting normal square states if check pass
			SetSquareState(ShapeXYpos(kx,ky,SP,2),ShapeXYpos(kx,ky,SP,6),state);
			SetSquareState(ShapeXYpos(kx,ky,SP,3),ShapeXYpos(kx,ky,SP,7),state);
			SetSquareState(ShapeXYpos(kx,ky,SP,4),ShapeXYpos(kx,ky,SP,8),state);
		}
	  else
		{
			SetSquareSolidState(ShapeXYpos(lx,ly,SP,1),ShapeXYpos(lx,ly,SP,5),state);  //setting solid square shape to last x,y position since new position will be colliding whith a solid block or bottom of square table
			SetSquareSolidState(ShapeXYpos(lx,ly,SP,2),ShapeXYpos(lx,ly,SP,6),state);		
			SetSquareSolidState(ShapeXYpos(lx,ly,SP,3),ShapeXYpos(lx,ly,SP,7),state);
			SetSquareSolidState(ShapeXYpos(lx,ly,SP,4),ShapeXYpos(lx,ly,SP,8),state);
			return false;                                                             //it allso returns false for the update shape function to know it needs to generate new shape
		}
	}
	
}
not sure exactly if this is an intended behavior to point us to bugs in run time or is just different default return values choosen by the release mode settings.

i may be wrong with what i've said here but since i found it i think i deserve an explanation :D

also (if possible) make sure to mention it in some future lesson ,i think u already said about type functions and that we must have a return statement ,altough i think some need to also know what happends if u miss it :lol:

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: changing luminosity by rgb values.(my tetris game proje

Post by chili » June 26th, 2012, 3:57 am

I dunno what you're talkin' about bro. I was talking about CheckBlockLineFULL(). In that function you have some flawed logic that causes it to exit the function without a return value specified.

If you don't return a value from a non-void function, the result is undefined and you cannot predict what will happen. It can vary depending on what build configuration you used, the order of your variables on the stack, the phase of the moon, etc.

Here is how you should have written that function:

Code: Select all

bool Game::CheckBlockLineFULL(int y)
{
	for(int x=0;x<10;x++)        
	{
		if(GetSquareSolidState(x,y)==EMPTY)
		{
			return false;
		}
	}
	return true;
}
Chili

User avatar
viruskiller
Posts: 399
Joined: June 14th, 2012, 5:07 pm

Re: changing luminosity by rgb values.(my tetris game proje

Post by viruskiller » June 26th, 2012, 1:45 pm

nah i don't think it was because i had the return false in an else condition,my fix for that was to put the x++ just before the x==10 check so it actually checks the last square too,the way i had it before it was checking without the last square,and it worked in release mode after that fix, although your idea is alot simpler lol,i tought i needed to check that all squares are empty when i just needed to check for a non empty square to return false..also the other way around for the other function.

anyway what i'm talkin' about is the shape going offscreen when moving to the left ,if u notice with vertical i shape or any other shape with at least 3 blocks in a line on the left side will just go trough border.that was because i missed a return true statement somwhere in the draw shape function,although i had no use for that function to return true ,the code worked fine in debug mode because there was nothing else to execute if the function returned true,but when in release mode it returned false because it was missing the return true statement ,wasn't paired.(same if,else idea,and only had return false on else.)

User avatar
viruskiller
Posts: 399
Joined: June 14th, 2012, 5:07 pm

Re: changing luminosity by rgb values.(my tetris game proje

Post by viruskiller » July 1st, 2012, 8:30 am

something strange started to happen with my game code:/,every first round it seems like the table square variable array is offset by 1, then after first round it shifts back to normal...tried to look into it but can't see why is getting offset:(

User avatar
viruskiller
Posts: 399
Joined: June 14th, 2012, 5:07 pm

Re: changing luminosity by rgb values.(my tetris game proje

Post by viruskiller » July 1st, 2012, 8:51 am

and i think i've hit the STACK end lol,it seems that after deleting the new created array's everything went back to normal lol,

Code: Select all

int SXT[16];
		int SYT[16];
		SQRState t[16]
so this 3 array's were just what it was needed to mess up my entire game,now i'm wondering ,do i really have to go trough memory allocation for a tetris game???
i've posted a new solution if any1 wants to look at it
Chili DirectX Framework.zip
look in game.h at user variables
(44.82 KiB) Downloaded 200 times

Post Reply