I have a class with the only constructor like this:
IntroScreen::IntroScreen(Game *game) :
View(game), counter(0.0f), message(-1), continueAlpha(255),
continueVisible(false), screenAlpha(255), fadeIn(false), fadeOut(false)
{
}
And somewhere in a method I have this if-statement
if (counter > 10.0f)
And Valgrind says for that line:
Conditional jump or move depends on uninitialised value(s)
But I initialized it in my initializer list! And I think I believe Valgrind. Because, sometimes everything goes correct and sometimes nothing happens…. So, maybe counter gets a wrong value and so it takes long until the counter reaches 10.
I already check my code where I use counter for some errors. But I think you can’t “un-initialize a value” with a C++ statement…
These are ALL the lines (except in the initializer list) where I use counter:
counter += speed;
counter = 20.0f;
counter += game->getSpeedFactor();
if (counter >= 15.f)
counter = 15.f;
if (counter > 10.0f)
Valgrind gives the same output for screenAlpha.
Both variables are private and I have no friend classes….
So, what is going on? What the problem could be?
Edit:
I printed the value out:
In the constructor, it was correnct: 0
In my method, it was rubbish. It prited random values like:
-97298.8...-106542.2...
The print statement is the first line of the method where all assignments to counter are in.
Second Edit:
Can this be the problem!!??
In my Game class, I initialize that IntroScreen like this:
Game::Game() : /* Some other stuff .... */ , view(new IntroScreen(this))`
{}
view is here a pointer to an abstract super-type of IntroScreen called View.
I found it:
getSpeedFactor()returns only the first time I call it a complete wrong number because of time-functions likegettimeofday(). The start value (to time how long it took to update the game) is set initialized to zero and the stop value is micros of the day: which gives a time of the whole day instead of the update time. Once the game loop ran once, the wrong value is corrected (because of the start value gets assigned). But the first time the game-logic was executed, I usedgetSpeedFactor()to assigncounter, so that waycounterget a value of -10000…Thanks all.