Negative value for Millisecs() ?

Monkey Targets Forums/Android/Negative value for Millisecs() ?

hub(Posted 2015) [#1]
Hi !
have a strange error with my program.

I use Millisecs() / 1000 and display it with drawtext. Sometimes it returns negatives values ? For example - 2351561

I use an Integer to store the value.

i'm trying to code an countdown. 10 to 0.

Thanks for your help.

Note : i've the same error if i use an extern function like this :



SLotman(Posted 2015) [#2]
It happens when your computer is turned on for a long period of time. The OS function that measure how many milliseconds your computer is on overflows, and turns into negative numbers.

From Microsoft:

Note that the value returned by the timeGetTime function is a DWORD value. The return value wraps around to 0 every 2^32 milliseconds, which is about 49.71 days. This can cause problems in code that directly uses the timeGetTime return value in computations, particularly where the value is used to control code execution. You should always use the difference between two timeGetTime return values in computations.



https://msdn.microsoft.com/en-us/library/windows/desktop/dd757629%28v=vs.85%29.aspx


hub(Posted 2015) [#3]
Thanks SLotman, also valid for Android ?
Note that the value decrease -19654, -19653, ...

So how to fix this with code ? I need a positive value that increase.

Thanks for your ideas !


abakobo(Posted 2015) [#4]
-19654+1= -19653 ... so it's an increase!

You can do as M$ say: record first millisec value and then get the difference with others, doesn't matter if it's negative or not, you will always get a positive number after the diffrence! Unless it happens at the very moment the time overflow occurs!


tiresius(Posted 2015) [#5]
On top of using a counter like abakobo says....

some people put in sanity checks that if the difference is <0 (negative) they fudge the number so you don't get any wacky results.