-
December 27th, 2010, 09:11 AM
#16
Re: Snake
Code:
static BOOL bKeyPressed;
static HBITMAP hBitmap;
are the two variables I want in my code.
If I compile it with them I have a problem.
If I compile without them I dont have a problem
Both these variables are put along with all other variables at the top of the WndProc Code
-
December 27th, 2010, 09:18 AM
#17
Re: Snake
Originally Posted by Igor Vartanov
Besides, this prototype looks really dangerous:
Code:
void MoveSnake(POINT pt[500][2],int iDirect,int iLength)
In case you cross the array bounds somehow, you spoil the stack with unpredictable behavior.
So what should the correct prototype be?
-
December 27th, 2010, 09:43 AM
#18
Re: Snake
remove the array size... just put.. POINT pt[][].. so that it takes enough memory by itself..
Code:
static BOOL bKeyPressed;
static HBITMAP hBitmap;
Make sure are these system defined variables or user defined.. if not . rename them to some other name... to avoid the clash..
-
December 27th, 2010, 10:09 AM
#19
Re: Snake
Originally Posted by vinayak4gargya
Breakpoint at switch (msg) of WndProc
Step Into;
Takes me to WM_PAINT:
Step Into : hdc = BeginPaint(hwnd,&ps);
Step Into again : I am returned back to switch(msg) (??) (The rest of the code of WM_PAINT is not executed)(??)
You must be careful when debugging WM_PAINT messages.
You cannot debug them if you have the debugger popup over your window. The reason is obvious -- each time the debugger is closed, your app window has to be repainted, causing another WM_PAINT message to be generated and the breakpoint is hit again. Then you continue the program, causing the app window to be exposed, meaning another WM_PAINT message is generated, which hits the breakpoint, then etc. etc. etc. You are basically in a "debugging" infinite loop of breakpoint, WM_PAINT, show app window, breakpoint, WM_PAINT, show app window, ...
The way you debug WM_PAINT messages is either
1) Make sure your Visual Studio debugger window does not intersect anyway with your main app window. This means that you have to resize your app and/or Visual Studio IDE window so that they do not overlap each other.
OR
2) You have a dual monitor setup, where your app is on one monitor, and your Visual Studio IDE is on the other monitor.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; December 27th, 2010 at 10:12 AM.
-
December 27th, 2010, 10:20 AM
#20
Re: Snake
Originally Posted by vinayak4gargya
So what should the correct prototype be?
This is much more flexible:
Code:
typedef double SnakeBoard[500][10];
void MoveSnake(SnakeBoard& myGameBoard,int iDirect,int iLength);
int main()
{
SnakeBoard sb;
MoveSnake(sb, 1, 1);
}
If you decide to use a different type, different dimensions, etc. all you need to do is change the typedef.
Regards,
Paul McKenzie
-
December 27th, 2010, 12:06 PM
#21
Re: Snake
This is just a guess but is it possible that MoveSnake() is somehow getting called recursively? Since you pass the address of an array I can imagine all kinds of problems if something is trying to modify the array whilst a previous call is still in the midst of modifying it.
I'd check for something like that before you start blaming the static variables. I can pretty much assure you that if your app breaks after you add those statics, it's just a coincidence.
In any case (forgive me if you already explained this) but is the problem seen after the mere fact of adding the static variables? Or does it only happen after your program modifies them?
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
December 28th, 2010, 01:18 AM
#22
Re: Snake
Done it!!!!!
There was definitely something overwriting the snake head!
Of course the weird scoreline!
See I print the scoreline --"Your Score __"
Well I had declared this to be a static char[10]...THAT was the problem.So everytime I wsprintf to update the score, it overwrote the snakes head.Now ive made it static char[15]
How Silly!! How so very silly!
Thanks a lot guyz I wouldnt have come back at this program without your help!
-
December 28th, 2010, 03:15 AM
#23
Re: [RESOLVED] Snake
As is now obvious, you'd introduced an error that was completely outside of the code samples you posted. I hope you understand now why you should never provide incomplete code fragments that only tell part of the story. For problems like this one you should always provide a minimal (but buildable) sample program that actually exhibits the problem.
Last edited by John E; December 28th, 2010 at 08:22 AM.
"A problem well stated is a problem half solved.” - Charles F. Kettering
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|