March 01, 2021, 04:49:35 AM

Author Topic: bug : millisecs() returns a negative decreasing value on Windows 10 (fixed)  (Read 2931 times)

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1152
Hello,

One of my procedure is working well on different computers with Windows XP and Windows 7, but not on a computer with Windows 10, and apparently this is caused by millisecs() which returns a negative decreasing value on Windows 10...

Here is an example :
Code: [Select]
Graphics3D(854,480,32,2)

Global MilliValue% = MilliSecs()

Global MainLoopTimer = CreateTimer(30)

Main()

End()

Function Main()

 Repeat

  If( KeyHit(28)=1 )
   MilliValue = MilliSecs()
  EndIf

  SetBuffer(BackBuffer())
  ClsColor(000,000,000) : Cls()
 
  Color(255,255,255)
  TStr$ = MilliValue : CText(TStr,GraphicsWidth()/2-StringWidth(TStr)/2,0)

  ;Flip(1)
  WaitTimer(MainLoopTimer)
  VWait():Flip(False)
 
 Until( KeyDown(1)=1 )

End Function

Function CText(TextStr$,PX%,PY%)

 Text(PX,PY,TextStr,False,False)

End Function

This is bad, so i guess that i will have to find a dll with a function to return the correct millisecond value on all Windows OS (XP, Vista, 7, 8, 10)

If you have one, please share it. (.dll and .decls)

Thanks,
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline therevills

  • Hero Member
  • *****
  • Posts: 616
Re: bug : millisecs() returns a negative decreasing value on Windows 10
« Reply #1 on: March 27, 2018, 09:59:21 AM »
Works okay on my Windows 10 machine, it outputted 1048160687... how long has the PC been on for or running your app?

Offline Derron

  • Hero Member
  • *****
  • Posts: 3410
Re: bug : millisecs() returns a negative decreasing value on Windows 10
« Reply #2 on: March 27, 2018, 10:04:15 AM »
Uptime > 28 days and it will wrap around the integer-limits.


bye
Ron

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1152
Re: bug : millisecs() returns a negative decreasing value on Windows 10
« Reply #3 on: March 27, 2018, 10:08:53 AM »
@therevills>>The computer has just been started a few minutes ago, and it was not in sleep mode...


@Derron>>the problem is not what you mention, because the value is negative and decreasing...


I have found a dll + decls with a function to get the millisecond value, i will test it. wait...
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1152
Re: bug : millisecs() returns a negative decreasing value on Windows 10
« Reply #4 on: March 27, 2018, 10:29:46 AM »
The dll + decls i have used was made by Bobysait, so probably functional...

Same result than with the Blitz3d millisecs() function :
On 2 computers with Windows 7, it returns the correct value (the 2 milliseconds values of the 2 functions are the same)
But on the computer with Windows 10, it returns a negative decreasing value (around -508100000) (the computer has just been started... and it was not in sleep mode)

weird ???
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline Steve Elliott

  • Hero Member
  • *****
  • Posts: 2963
  • elgol 2021
Re: bug : millisecs() returns a negative decreasing value on Windows 10
« Reply #5 on: March 27, 2018, 10:44:33 AM »
Quote
Works okay on my Windows 10 machine

Same here, works fine.
Windows 10 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
MacOS Big Sur 64-bit, 8Gb RAM, Intel i5 2.3 Ghz, Intel Iris Plus Graphics 640 1536 MB
Linux Mint 19.3 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
Raspberry Pi 400, Pi4, BBC B, C64, ZX Spectrum

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1152
Re: bug : millisecs() returns a negative decreasing value on Windows 10
« Reply #6 on: March 27, 2018, 10:51:51 AM »
So how is this possible ? And what can i do about it ? is there a way to reset the milliseconds value to 0 and to set the "timer" to increase instead of decrease ?

The easy approach would be to disregard buggy computers :P
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline Naughty Alien

  • Hero Member
  • *****
  • Posts: 701
Re: bug : millisecs() returns a negative decreasing value on Windows 10
« Reply #7 on: March 27, 2018, 10:55:43 AM »
..did you implement rollover timer function?

Offline TomToad

  • Hero Member
  • *****
  • Posts: 543
Re: bug : millisecs() returns a negative decreasing value on Windows 10
« Reply #8 on: March 27, 2018, 11:08:15 AM »
Find other development tools, such as BlitzMax, AGK, C++, etc... See if the problem exists in any of those.  Could be you have a defective timer.  Try
Code: [Select]
Graphics3D(854,480,32,2)

Global MilliValue% = (MilliSecs() And $7FFFFFFF) / 1000

Global MainLoopTimer = CreateTimer(30)

Main()

End()

Function Main()

 Repeat

  If( KeyHit(28)=1 )
   MilliValue = (MilliSecs() And $7FFFFFFF) / 1000
  EndIf

  SetBuffer(BackBuffer())
  ClsColor(000,000,000) : Cls()
 
  Color(255,255,255)
  TStr$ = MilliValue : CText(TStr,GraphicsWidth()/2-StringWidth(TStr)/2,0)

  ;Flip(1)
  WaitTimer(MainLoopTimer)
  VWait():Flip(False)
 
 Until( KeyDown(1)=1 )

End Function

Function CText(TextStr$,PX%,PY%)

 Text(PX,PY,TextStr,False,False)

End Function
This should count up by 1 second intervals.  Let it run for about 10 seconds, then press enter to see if the timer has advanced 10 seconds or not.  Try 30 or a minute.  Is it keeping correct time?
------------------------------------------------
8 rabbits equals 1 rabbyte.

Offline Henri

  • Sr. Member
  • ****
  • Posts: 294
Re: bug : millisecs() returns a negative decreasing value on Windows 10
« Reply #9 on: March 27, 2018, 04:13:14 PM »
My first impression was overflow issue.

In NG you could resolve it by using unsigned variables like:
Code: BlitzMax
  1. While Not KeyHit(KEY_ESCAPE)
  2.        
  3.         Print GetTickCount() + " | " + GetTickCount64()
  4.        
  5.         Delay 1000
  6.         PollSystem()
  7. Wend
  8.  
  9. Print "END"
  10.  
  11. Extern "Win32"
  12.         ' https://msdn.microsoft.com/en-us/library/windows/desktop/ms724408(v=vs.85).aspx
  13.         Function GetTickCount:UInt()="UInt GetTickCount() !"    ' Unsigned 32bit
  14.         Function GetTickCount64:ULong()="ULong GetTickCount() !" ' Unsigned 64bit
  15. EndExternn

Doing the same in Blitz3d requires some jiggery-pokery :-)

-Henri
- Got 01100011 problems, but the bit ain't 00000001

Offline Derron

  • Hero Member
  • *****
  • Posts: 3410
Re: bug : millisecs() returns a negative decreasing value on Windows 10
« Reply #10 on: March 27, 2018, 05:36:27 PM »
@ Henri
I thought that too but RemiD ruled that out.


bye
Ron

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1152
Re: bug : millisecs() returns a negative decreasing value on Windows 10
« Reply #11 on: March 27, 2018, 07:53:33 PM »
What is strange is that each time, the computer has just been started, and was not in sleep mode, so in theory the milliseconds value should start at 0 and increase (until it reaches 2147483647 (in Blitz3d) which would be after 24.85 days...)

I will output a text file with milliseconds values during a few seconds and post it here, maybe it will give you some ideas...
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1152
Re: bug : millisecs() returns a negative decreasing value on Windows 10
« Reply #12 on: March 27, 2018, 08:04:27 PM »
here the milliseconds values during 5seconds :
http://rd-stuff.fr/milliseconds-values-during-5seconds.txt

apparently the value increases, unlike what i said previously, because a smaller negative value is nearer to 0 ???

but what i am supposed to do with that ? i don't want to have to rewrite all my procedures just for this weird computer...
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline Derron

  • Hero Member
  • *****
  • Posts: 3410
Re: bug : millisecs() returns a negative decreasing value on Windows 10
« Reply #13 on: March 27, 2018, 08:34:14 PM »
if the value increases this is that "rollover thing".

It reaches its maximum and continues then at the integer minimum. You will need to replace your Millisecs-calls with something different - see the code by tomtoad:
Global MilliValue% = (MilliSecs() And $7FFFFFFF) / 1000

to get an idea...


In my Dig-Framework I use this:
Code: BlitzMax
  1.         'returns the time gone since the computer was started
  2.         Function MilliSecsLong:Long()
  3.                 'code from:
  4.                 'http://www.blitzbasic.com/Community/post.php?topic=84114&post=950107
  5.  
  6.                 'Convert to 32-bit unsigned
  7.                 Local Milli:Long = Long(Millisecs()) + 2147483648:Long
  8.                  'Accumulate 2^32
  9.                 If Milli < LastMilliSeconds Then MilliSeconds :+ 4294967296:long
  10.  
  11.                 LastMilliSeconds = Milli
  12.                 Return MilliSeconds + Milli
  13.         End Function
  14.  


As you recognized already: the value does increase, so "new value" minus "old value" will result in the "time gone". An "if new - old > 1000 then OneSecondIsGone()" should work regardless of the rollover issue.


bye
Ron

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1152
Re: bug : millisecs() returns a negative decreasing value on Windows 10
« Reply #14 on: March 27, 2018, 09:04:51 PM »
ok but what does (MilliSecs() And $7FFFFFFF) does ? compared to only MilliSecs()


btw my problem is not to keep track of milliseconds time, but rather to give a milliseconds value to an entity after it has been updated, and to use these milliseconds values to order the entities from lowest value to highest value, so that the entity which was updated the more time ago, is updated next. but these negative milliseconds values somehow makes my procedure bug...
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal