Page 1 of 1

Beginner Tutorial 17 Framertimer

Posted: August 28th, 2019, 2:44 pm
by hannes321123
Hi everyone,

I have a problem to understand an error I made in tutorial 17. In Frametimer.cpp in the mark-function there is a line "last = steady_clock::now();" I know that "last" is a member variable declared by us but I accidentally wrote an "auto" in front off it, that caused a huge acceleration. Investigating it further by writting "steady_clock::time_point" instead of "auto" the acceleration remaind... What is happening there?

Thanks already
hannes

Re: Beginner Tutorial 17 Framertimer

Posted: August 28th, 2019, 8:36 pm
by Yumtard
What's happening is that you're creating another variable called last which is local to the mark function

At the beginning of the function you also create a variable old and set its value to the member variable last.
The value of the member variable never changes though since, as we established you're making a new local variable when you're going:
auto last = steady_clock::now();

This leads to an acceleration because when you're calculating the frame time you're doing
last - old
last in this case refers to the local variable which stores the current time
old in this case has the same value as the member variable last, which never changes
causing the delta time to grow larger

Re: Beginner Tutorial 17 Framertimer

Posted: August 30th, 2019, 3:17 am
by chili
Scope is an essential concept to master for sure :D

Re: Beginner Tutorial 17 Framertimer

Posted: September 1st, 2019, 4:02 pm
by hannes321123
Thanks a lot, the explanation was very helpful. Sorry for answering late. I have been working mostly with Matlab there you have to declare less stuff and things are more seperated. Thanks to all the people working on the tutorials and in the forum, it is great !!!