Skip to main content
GameDev.net gamedev.net
🔒 Locked

Weird C++ Behavior

Started by Trireme Mar 9, 2003 at 2:38 PM 2 replies 200+ views
Original Post
Trireme
Trireme
Alright, I'm completely confused, I've spent many hours pondering this and I cannot come to a solution. Working on an isometric tile engine, and I just can't seem to figure out what's wrong.
  
if (scroll.scrolly < floor(10 - .5 * scroll.scrollx)) {
//Move to tile up and to the left

	if (scroll.camy % 2 == 1) {
	scroll.camx = scroll.camx - 1;
	}
	scroll.camy = scroll.camy - 1;
	scroll.scrollx = scroll.scrollx+20; //x offset moves +20

	scroll.scrolly = scroll.scrolly+11; //y offset moves +11

}

if (scroll.scrolly > floor(-.5*(scroll.scrollx-10) + 20)) {
//Move to tile down and to the right

	if (scroll.camy%2 == 0) {
	scroll.camx = scroll.camx + 1;
	}
	scroll.camy = scroll.camy + 1;
	scroll.scrollx = scroll.scrollx-20; //x offset moves -20

	scroll.scrolly = scroll.scrolly-11; //y offset moves -11

}

if (scroll.scrolly > ceil(.5*scroll.scrollx + 10)) {
//Move to tile down and to the left

	if (scroll.camy%2 == 1) {
	scroll.camx = scroll.camx - 1;
	}
	scroll.camy = scroll.camy + 1;
	scroll.scrollx = scroll.scrollx+20; //x offset moves +20

	scroll.scrolly = scroll.scrolly-11; //y offset moves -11

}

if (scroll.scrolly < ceil(.5*(scroll.scrollx-10) + 20)) {
//Move to tile up and to the right

	if (scroll.camy%2 == 0) {
	scroll.camx = scroll.camx + 1;
	}
	scroll.camy = scroll.camy - 1;
	scroll.scrollx = scroll.scrollx-20; //x offset moves -20

	scroll.scrolly = scroll.scrolly+11; //y offset moves +11

}
  
This bit of code stops my program. It just STOPS. Locks up completely, can't move, only ways to get out of it are A) Unplug, or B) Hold in the sleep button on my keyboard for 15-30 seconds until the comp goes to sleep, then wake it up and the program is minimized and I can get rid of it. Now, if you have JUST
  
if (scroll.scrolly < floor(10 - .5 * scroll.scrollx)) {
//Move to tile up and to the left

	if (scroll.camy % 2 == 1) {
	scroll.camx = scroll.camx - 1;
	}
	scroll.camy = scroll.camy - 1;
	scroll.scrollx = scroll.scrollx + 20;	//x offset moves +20

}
  
(notice the missing scroll.scrolly =... line) and not the moving in the other three directions, it doesn't die. However, if you put any of those other three, BOOM, death. I did some tests to check possible causes, and I can tell you this... scroll.camx and scroll.camy can be any integers. There's no value for these that will cause this problem. Similarly, scroll.scrollx and scroll.scrolly can be any integer, with no problems(cept for the fact that it makes my map all funky, but it doesn't crash). Does anybody have ANY idea what's going on? I had a similar problem before as well, in which you could have any ONE of those four if... statements, but if you have any combination of two of them, it causes instant death. I'm totally lost here. ...By the way, if you take out that code it all runs fine, except of course that the scrolling doesn't work right. [edited by - Trireme on March 9, 2003 3:40:45 PM] [edited by - Trireme on March 10, 2003 5:14:53 PM]
Mathematix
Mathematix
With all due respect, you are aware that your code is a type-casting mess. It is littered with implicit casts, for example the mod operator (%) only works with integers and the floor() and ceil() functions work in double precision.

You will need to rewrite your code to avoid such conflicts.

As for the crashing thing, that''s to do with elsewhere in your code.
Qw3r7yU10p!
Qw3r7yU10p!
You could use the [source ] [/source ] tags to make your code nice and easy for us to read.
Sneftel
Sneftel
Have you run your code in a debugger yet to see where it stops?


But... but that''s what HITLER would say!!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.