PDA

View Full Version : Bizarre Problem in printf


mt_maui
2006.11.30, 11:34 PM
Alright, I've been banging my head against the wall with this problem, ran the debugger over it, and just can't make head or tale of what exactly is happening.
Here's the offending line of code:


if(runningTurn) {
turnCounter = (SDL_GetTicks() - turnStart) / 10;
printf("turn: %d\n", turnCounter);

if(turnCounter >= currentPath.getLength()) {
printf("pathLength:%f\n", currentPath.getLength()); //causes lockup

turnCounter = 0;
runningTurn = false;
} else {
//gTestDot.positionToPoint(currentPath.getCurrentPoi nt(turnCounter));
}
}

The weird thing is, this program runs fine if I comment out that second printf(), but locks up when I leave it in as soon as runningTurn becomes true, without even printing the output of the first printf statement.

In the debugger, it shows that it gets the return value from the getLength() function successfully, and goes unresponsive when the thread box shows "prinft$LDBLstub".

:mad:I'm going crazy right now, this makes no sense to me. I can forget about this thing and focus on finals, I've never seen anything like it. Anyone have any clue what could be causing this?

OneSadCookie
2006.11.30, 11:46 PM
what does currentPath.getLength() return? If it's not a float or a double, that could cause problems.

mt_maui
2006.11.30, 11:56 PM
It returns a float.
Even more annoying, this same line of code runs fine elsewhere in the program... :(
I'm starting to get the feeling that this isn't a problem that can be solved by looking at this one section of code. Does this sound like something that could be caused by a memory error or something like that?

OneSadCookie
2006.12.01, 12:41 AM
Yeah, my next stop'd be guard malloc, and hope your program crashes somewhere else.

mt_maui
2006.12.01, 03:33 AM
No luck with that. On the bright side, I didn't know anything about malloc-guard before, and after getting your advice I found a few good articles on it and how it is useful.

For now I'm just going to change the code so it works, and switch some parameters that depended on time over to framerate so that the code is a little easier to debug. Hopefully that'll make the problem a little bit less mysterious.