SyntaxBomb - Indie Coders

Languages & Coding => Blitz2D, BlitzPlus, Blitz3D => Topic started by: RemiD on March 27, 2018, 09:38:21 AM

Title: bug : millisecs() returns a negative decreasing value on Windows 10 (fixed)
Post by: RemiD on March 27, 2018, 09:38:21 AM
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,
Title: Re: bug : millisecs() returns a negative decreasing value on Windows 10
Post by: therevills 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?
Title: Re: bug : millisecs() returns a negative decreasing value on Windows 10
Post by: Derron on March 27, 2018, 10:04:15 AM
Uptime > 28 days and it will wrap around the integer-limits.


bye
Ron
Title: Re: bug : millisecs() returns a negative decreasing value on Windows 10
Post by: RemiD 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...
Title: Re: bug : millisecs() returns a negative decreasing value on Windows 10
Post by: RemiD 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 ???
Title: Re: bug : millisecs() returns a negative decreasing value on Windows 10
Post by: Steve Elliott on March 27, 2018, 10:44:33 AM
Quote
Works okay on my Windows 10 machine

Same here, works fine.
Title: Re: bug : millisecs() returns a negative decreasing value on Windows 10
Post by: RemiD 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
Title: Re: bug : millisecs() returns a negative decreasing value on Windows 10
Post by: Naughty Alien on March 27, 2018, 10:55:43 AM
..did you implement rollover timer function?
Title: Re: bug : millisecs() returns a negative decreasing value on Windows 10
Post by: TomToad 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?
Title: Re: bug : millisecs() returns a negative decreasing value on Windows 10
Post by: Henri 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
Title: Re: bug : millisecs() returns a negative decreasing value on Windows 10
Post by: Derron on March 27, 2018, 05:36:27 PM
@ Henri
I thought that too but RemiD ruled that out.


bye
Ron
Title: Re: bug : millisecs() returns a negative decreasing value on Windows 10
Post by: RemiD 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...
Title: Re: bug : millisecs() returns a negative decreasing value on Windows 10
Post by: RemiD 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...
Title: Re: bug : millisecs() returns a negative decreasing value on Windows 10
Post by: Derron 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
Title: Re: bug : millisecs() returns a negative decreasing value on Windows 10
Post by: RemiD 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...
Title: Re: bug : millisecs() returns a negative decreasing value on Windows 10
Post by: RemiD on March 27, 2018, 09:27:13 PM
ok, what TomToad suggested ( using (MilliSecs() And $7FFFFFFF) instead of Millisecs() ) apparently works, it returns a positive value which increases. Good ! thanks.

The other workaround that i have found was to set the initial MilliValue for each entity to -2147483647+I (I being the index number of the entity)

Thanks TomToad ! :)
Title: Re: bug : millisecs() returns a negative decreasing value on Windows 10 (fixed)
Post by: grindalf on March 27, 2018, 09:31:33 PM
I was also having this problem in my game on win10 but for me it doesn't always happen(seems to only happen if my computer has been in sleep mode) Turning the computer off and back on solves it. I have rewritten my code now so I no longer have the issue
SimplePortal 2.3.6 © 2008-2014, SimplePortal