CreateTimer(1000) vs CreateTimer(1001)

BlitzPlus Forums/BlitzPlus Programming/CreateTimer(1000) vs CreateTimer(1001)

Idiot(Posted 2004) [#1]
Is anyone else seeing this strange behavior in Blitz+?

The following code seems to ignore the timer entirely.
window=CreateWindow("WHOOPS",0,0,100,100)
canvas=CreateCanvas(0,0,100,100,window)
SetBuffer CanvasBuffer(canvas)
timer=CreateTimer(1000)

Repeat
	Cls
	Text 0,0,MilliSecs()

	FlipCanvas canvas

	WaitTimer(timer)

Until KeyDown(1)


However, if you change the 1000 to 1001, the program freezes.

Can anyone duplicate this?


Idiot(Posted 2004) [#2]
Is that a no?


Beaker(Posted 2004) [#3]
Same odd behaviour here.


Floyd(Posted 2004) [#4]
I guess this means that one millisecond is the smallest measurable time interval.

CreateTimer(1000) makes the interval exactly 1/1000 of a second.
This is the smallest possible 'clock tick'.


Mr Brine(Posted 2004) [#5]
weird city


Idiot(Posted 2004) [#6]
So why does it freeze with 1001?


Richard Betson(Posted 2004) [#7]
In my opinion this looks like a bug. It should not freeze like that.

In addition, I ran IDIOT's code (1001 part) and it froze up. Any other code I ran after this that used wait timer seem to lock up as well even though it was well below 1001 , in my case 30.

If you have not already, post this in the B+ bug section. Your likely to get the obligatory "don't use a timer over 1000" comment, but B+ should be solid enough to not lock-up if you were to use 1001+.

BTW...

Nice to see you around IDIOT! :)

L8r,


Stoop Solo(Posted 2004) [#8]
I have had some strange stuff with createtimer. If my memory serves me correctly I was even experiencing lock-up. I ended up having to use...

z=targetspeed-(MilliSecs()-loopspeed)
If z>0 Then Delay z
loopspeed=MilliSecs()

...instead.


Richard Betson(Posted 2004) [#9]
There are other issues with WaitTimer() I know Mark is aware of, but this seems new. :)

L8r,


Idiot(Posted 2004) [#10]
Well, I found it trying to get around another problem. I'm writing an updated pixel ruler program using the borderless window feature (which is really cool BTW). But it's spiking the CPU with like 90%+ usage, and I'm trying to decrease that as much as possible (or at all really). I can't use waitevent() because I constantly have to draw a line where the mouse is. I was hoping having a slow timer would do something, but it doesn't, and there's that bug. Any ideas?


Eikon(Posted 2004) [#11]
Dont know if this will help but it sounds like just what your looking for:

[a ftp://user:blitz@eikon.myftp.org/eiksoft/ruler.txt]ftp://user:blitz@...
[/a]
Low cpu usage too.


Idiot(Posted 2004) [#12]
Neat! Not exactly what I was making, but it has the exact same name!


Eikon(Posted 2004) [#13]
Thanks. If your ruler goes big (huh huh) I will humbly change mine ;)


Idiot(Posted 2004) [#14]
Haha, don't worry about it. I need to stop naming all my Blitz+ projects Something+.

And it's not going anywhere if I can't get the CPU usage down.

Why is there no way to set the process priority in Blitz? I've seen other programs that let you change their priority, I wish you could set it for your Blitz programs.


Eikon(Posted 2004) [#15]
Well Idiot it might be possible with the following api:
SetThreadPriority
SetPriorityClass
but im no good with userlibs.


Richard Betson(Posted 2004) [#16]
@Idiot

I'm having the same CPU throttle problem for screen savers and my media player. This is a problem I'm sure Mark is aware of but needs to address. :)

L8r,


Jay Mattis(Posted 2004) [#17]
Using the Delay command in your game loop frees up CPU usage.


Richard Betson(Posted 2004) [#18]
I would prefer thread control or even slice control. :)

L8r,


Idiot(Posted 2004) [#19]
I think using waitevent(10) or such will do what I want, I think I was confused about that in the same way I was confused about waittimer()... smaller number=longer wait.