weird double values on cout

Hello!

Here is code first:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//fp_screen.h
class fp_screen{
	public:
double fps;
double xx3;


// fp_Screen.cpp
fp_screen::init() // called before everything
{
fps = 0.0;
xx3 = 0.0;
}

bool fp_screen::frame()// called everyframe
{
fps = 1.0 / xx3;
// if i put cout here everything is fine
// in main_frame() things get weird
// im only checking screen.fps not changing value there
r = main_frame();
}

// main.cpp
void main_frame()
{
cout << "fps:" << screen.fps << endl;
}



fps:1.16922e+006 // this will happen 80%
fps:900 // this is how it should be

if i do
cout << "fps:" << (int)screen.fps << endl;
somethings number is right like 800 or else
put sometimes its 5423423... something.


What is going on here?
Last edited on
You probably printing uninitialized value of fps. Make sure that init is surely called, and better move init code to the constructor or call it from constructor.
Updated code.

I think i know what the problem is.
If that fps get too big like 2000 or something it will do that thing.
Last edited on
xx3 = 0.0;

fps = 1.0 / xx3;
Err, division by 0? Post full code, there is still too little information to be sure.
gametime = (double)(xx10.QuadPart - xx12.QuadPart) / xx1;
xx3 = gametime - xx4;
xx4 = gametime;
fps = 1.0 / xx3;

They are all initalized correctly.
edit, test xx3 with cout, working fine.
Last edited on
Problem solved i think.

1
2
3
4
5
6
// I calculate fps outside here
	if( xx5 < gametime )
	{
		r = main_frame();
		xx5 = gametime + xxfps_max;
	}

The problem is when im not calling that main_frame
my fps will be 1000000 something.
1.0 / 1000000
will give so many you know, those numbers what come after '.'
Anyway, everything is working fine i guess.
I did not believe that my fps can be so big when i'm not calling main_frame
I guess i should really check out the reason why after calling main_frame fps will be 2000 <

Topic archived. No new replies allowed.