Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

-Thork-

if () statement jumping to 0x00000000

This topic is 5888 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve got a WndProc function which has the standard switch () statement for parsing the WM_* messages. One of my case labels is a WM_KEYDOWN message. I''ve tried two methods to parse what key has been pressed. I first used a switch statement with VK_UP, VK_DOWN, VK_LEFT, and VK_RIGHT and afterwards I tried four if statements with the same keycodes. However, whenever the program got to the if or switch statement, the application jumped to 0x00000000 and caused an access violation. Any ideas as to why this could be? Any help would be much appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Here''s the code. The program is a client/server for a game. Basically what the code should do is if the program is running as a client and a key is pressed, then data is sent back to the server about what key was pressed.


  
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_KEYDOWN:
char transmit[4];
GAMEMSGHEADER gmh;
int keycode;
memset(transmit, 0, 4);
gmh.ID = ''D'';
gmh.usSize = 1;
memcpy(transmit, &gmh, sizeof(GAMEMSGHEADER));
keycode = (int)wParam;

if (bClient) {
if (keycode == VK_UP) {
transmit[sizeof(GAMEMSGHEADER)] = 0;
Cli_SendData(transmit, 4);
}
if (keycode == VK_RIGHT) {
transmit[sizeof(GAMEMSGHEADER)] = 1;
Cli_SendData(transmit, 4);
}
if (keycode == VK_DOWN) {
transmit[sizeof(GAMEMSGHEADER)] = 2;
Cli_SendData(transmit, 4);
}
if (keycode == VK_LEFT) {
transmit[sizeof(GAMEMSGHEADER)] = 3;
Cli_SendData(transmit, 4);
}
}
break;


There are a few more WM_* messages after this, but the error occurs during the...
if (keycode == VK_UP) {
...line of code. The dissassembly doesn''t reveal much either. As far as I can tell, the "jne" command is jumping to the correct location, but the program just jumps out to 0x00000000, the call stack is emptied and an access violation ensues.

Share this post


Link to post
Share on other sites
I think it''s started working...it''s amazing what a simple ''restart-the-computer'' can do...

Share this post


Link to post
Share on other sites
quote:
Original post by Mayrel
Are you smashing the stack? Is sizeof(GAMEMSGHEADER) 4 or less? Munging the stack can lead to all sorts of odd errors.

Ah, you got it first . You mean 3 or less, but it''s just a typo.

Share this post


Link to post
Share on other sites
Yeah, sizeof(GAMEMSGHEADER) is 3 (well it was 4, before i put in "#pragma pack(1)", as with the size it 4 it was causing more errors...). Nevertheless, the if statement is working now.

Thanks anyway.

Share this post


Link to post
Share on other sites
To go on a tangent: You should put a set of braces are the case statement if you''re declaring variables in it. For example:

switch(asdf) {
case ALPHA: {
int a;
}
break;
}

Otherwise the compiler can (rightfully) be confused about whether or not to declare something.

Share this post


Link to post
Share on other sites
Hmm, yeah. I hate writing Network programs using only one computer. Trying to run a client game and a server game on one computer is just asking for trouble.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!