Jump to content
  • Advertisement
Sign in to follow this  
Frequist

Oddest error I have ever seen....

This topic is 5100 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

In my program I have these lines...
intObjectX = (signed short int)(intObjectX/2);
intObjectY = (signed short int)(intObjectY/2);
I've ran a messagebox to determine which value this is returning....
sprintf(chrDebug,"X=%iY=%i",intObjectX,intObjectY);
MessageBox(hwnd,chrDebug,"Ja",0);
The values that get returned are as followings... intObjectX was equal to 351. intObjectY was equal to 161. These values were expected, and should not have crashed my program. I rewrote the code with this...
intObjectX = 351;
intObjectY = 161;
And the program works. Whats the difference; why is it crashing when I use the prevoius code?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Sneftel
Have you run the program in the debugger to see what's going on?


Debugger? No, I've never used that before.

If you want my opinion, I think its something todo with the way the numbers get stored after being divided by 2.. but I can't make sence of it. [bawling]

Share this post


Link to post
Share on other sites
My compiler gives me trouble when I try to declare a variable or typedef using the keyword 'signed'. (not that it helps you). I hope somebody replies with the solution to your problem...

Share this post


Link to post
Share on other sites
Perhaps now is a good time to start, then. If you don't know how to use the debugger effectively, you are doomed to waste hours and hours debugging with messageboxes and such.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
Perhaps now is a good time to start, then. If you don't know how to use the debugger effectively, you are doomed to waste hours and hours debugging with messageboxes and such.


Yah... gotta love it when you put a MessageBox in a loop. [bawling].

@odiousangel

I would avoid it.. but I have to use signed variables since the map editor is writen in VB, and can't save unsigned integers. [bawling].

Thanks though... btw I'm Visual C++ 6.

Share this post


Link to post
Share on other sites
You're going to have to post alot more code then that if you want to get help from us. We're not mind readers ya know (some of us aren't even code readers ;)). Debuggers are very important tools; you should always know how to use the debugger for you language and/or compiler.
Quote:

I would avoid it.. but I have to use signed variables since the map editor is writen in VB, and can't save unsigned integers.

Integers are assumed to be signed in C++ if not specified.

Share this post


Link to post
Share on other sites
Quote:
Original post by Frequist
If you want my opinion, I think its something todo with the way
the numbers get stored after being divided by 2..


1. Use a debugger.

2. I dont think that the division itself is the reason for your crash. I would guess that you somewhere have some kind of memory problem, probably writing into undecladered memory or out of bound from an array.

Just because your bug does not happen does not mean that its gone. It is a common misconception that a bug only exists when it crashes the program. Your program can compile and run fine and still have bugs inside...

Share this post


Link to post
Share on other sites
bytecoder,

It would be a couple dozen pages of code to show you all the places where it gets read...

btw.. I started working with the VC debugger... (Its easier then I thought). I found the error occured on this region

	if (bytPlayers == 1)
{
/* Get the UpperLeft Tile Coordinates */
intX = (unsigned short int)((intP1CameraX - 160)/16);
intY = (unsigned short int)((intP1CameraY - 160)/16);


bytOffSetX = (intP1CameraX - 160) - (intX * 16);
bytOffSetY = (intP1CameraY - 160) - (intY * 16);

/* BitBlt the Tiles */
for(bytTileX = 0; bytTileX < 21; bytTileX++)
{
for(bytTileY = 0; bytTileY < 14; bytTileY++)
{
/* Generate correct tile coordinates from the map array. */
fltPart1X = (float)arrMap[bytTileX + intX][bytTileY + intY]/13;
intInterY = fltPart1X;
fltPart1X = (float)(fltPart1X - intInterY);
intInterX = fltPart1X * 13 +0.2f;

/* Draw the Map */
BitBlt(hdcGame, (bytTileX * 16) - bytOffSetX, (bytTileY * 16) - bytOffSetY, 16, 16, hdcTiles, (intInterX * 16), (intInterY * 16), SRCCOPY);
RedrawWindow(hwnd, 0, 0, 1);
}
}
}


What the debugger set was...
intP1CameraY is equal to 144 (Not so good.)
intX is equal to 14 (Which is good)
intY is equal to 65535 (Uhm.. HOW?! Its not even UNSIGNED)

(intY - 160) = Negative Value (This shouldn't EVER happen).
There is a problem with my intP1CameraY initiate code it would appear, but why does presetting the devision value fix it.

[Edited by - Frequist on July 7, 2004 4:24:13 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by schue
Quote:
Original post by Frequist
If you want my opinion, I think its something todo with the way
the numbers get stored after being divided by 2..


1. Use a debugger.

2. I dont think that the division itself is the reason for your crash. I would guess that you somewhere have some kind of memory problem, probably writing into undecladered memory or out of bound from an array.

Just because your bug does not happen does not mean that its gone. It is a common misconception that a bug only exists when it crashes the program. Your program can compile and run fine and still have bugs inside...


That fact that precalculating the result of the devision statement made the program work, really convinces me there is a problem with how the result of the division is being stored.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!