GetTickCount() gives negative integer
#1

When I run my server on our Dedicated GetTickCount() returns a negative number, which is weird considering what gtc actually does. This happens at every restart so it's not a problem of the int being wrapped.

Debug:
Код:
GetTickCount() returned [-1435050682]
GetTickCount() returned [-1435042638]
Anyone had this problem before and cares to elaborate?
Reply
#2

i don't know about samp's GetTickCount
but in VB.NET "GetTickCount will return a negative number if your system has not been rebooted in approx 24.8 days."
Reply
#3

What exactly do you want to do? Using only this one function may return negative or positive with lots of numbers..
Reply
#4

Quote:
Originally Posted by SA-MP Wiki
GetTickCount will cause problems on servers with uptime of over 24 days (physical server, not SA:MP server) as GetTickCount will eventually warp past the integer size constraints
GetTickCount
Reply
#5

hm.. what happens if you bitwise AND the result with all but the most significant bit? e.g.
Код:
new Tick=GetTickCount()&0x8fffff;
...this eliminates the most significant bit (the 32'th is the sign of an integer), just erasing the minus?

i never had such issues with that function, so i cant replicate it

edit: oops, its not 0x8fffff, its indeed 0x7fffff - 0x7==0b0111 first bit set to 0
Reply
#6

Id explain it like this:
GetTickCount returns the ms since the server started, so internally it will look like this:
Код:
int millitimeAtStart;
int GetTickCount() {
    return (currentMillis() - millitimeAtStart);
}
Now the problem is, upon server restart, millitimeAtStart is reinitialized with some weird value. It just gets the correct value at some later time. And in between it returns random, sometimes negative values for a short period.
Reply
#7

I've restarted our (physical) server, I'll have to wait for the sysadmin to hop online before I know if it worked though. Thank you for the advice.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)