Strange unlock screen behavior

Geoff Canyon gcanyon at gmail.com
Sun Oct 20 04:24:06 CEST 2013


I'm doing a little space simulation as an experiment. Everything is working
properly, but one aspect is very puzzling. The basic loop is:

1. Lock the screen.
2. Calculate updates to the position of the ship.
3. Relocate the ship graphic. It's just a 5-pixel circle.
4. Unlock the screen.

I noticed that the ship was speeding up and slowing down, so I started
profiling the code. the first step was to measure the issue:

1. Put the long seconds into T
2. Lock the screen.
3. Calculate updates to the position of the ship.
4. Relocate the ship graphic. It's just a 5-pixel circle.
5. Unlock the screen.
6. Report the long seconds - T

Sure enough, sometimes the above takes .017 seconds, other time as much as
.035 seconds. I eventually narrowed it down to this:

1. Lock the screen.
2. Calculate updates to the position of the ship.
3. Relocate the ship graphic. It's just a 5-pixel circle.
4. Put the long seconds into T
5. Unlock the screen.
6. Report the long seconds - T

In other words, oddly enough, the mere act of unlocking the screen varies
in terms of the time it takes by as much as 2x. It gets weirder.

As near as I can tell, the slowdown occurs whenever the ship graphic is
moving away from 0,0. Updates are fast when the ship is moving toward 0,0.

The ship is in a group, by itself -- the code can handle multiple ships,
but I'm testing with just one. That group is in another, which contains the
planets, etc.

I haven't been able to replicate the issue in stripped-down code. I did get
this to show me something odd:

on mouseUp
   put empty into fld "log"
   repeat 50
      lock screen
      get the loc of grc 1 of grp "ships"
      add 1 to item 2 of it
      set the loc of grc 1 of grp "ships" to it
      put the long seconds into profileTime
      unlock screen
      put round(1000 * (the long seconds - profileTime)) & cr after fld
"log"
      wait 2 ticks
   end repeat
end mouseUp

if I run that, I get results like this:

1
1
1
1
3
8
1
1
1
6
1
1
11
1
1
8
1
3
10
1
1
1
1


Most of the time, unlocking the screen is extremely fast, but sometimes it
takes much longer. Any ideas?


More information about the use-livecode mailing list