# android game - lock_layer timed out

I'm developing a (scroll) game and i'm getting weird messages in LogCat:

• lock_layer() timed out but didn't appear to need to be locked and we recovered(..)
• lock_layer timed out (is the CPU pegged?)...
• executeScheduledBrodcasts() skipped, contention on the client. We'll try again later.

it looks like the rendering takes too long and causes the warning (i'm drawing ~ 50 images every frame), but is this the emulator fault? When i test it on a device (sony ericsson xperia x8), running 1.6, i don't see any lag or any performance drops (i get ~ 60fps). I get this warning only in android 1.6.

Should i ignore it? Could it cause the game to crash? Am i doing something horribly wrong or is it a bug?

Run code:

  while(running) {
try {
c = holder.lockCanvas(null);
synchronized(holder) {
// getElements - returns a Vector of elements to be drawn relative to camera
elements = collection.getElements(cameraX,cameraY,cameraWidth,cameraHeight);
for(int i =0 ; i < elements.size(); i++) {
// draw the element according to camera
c.drawBitmap(image,elements.get(i).x,elements.get(i).y);
}
}

} finally {
holder.unloackCanvasAndPost(c);
}


}

• Are you running a fixed timestep, with a variable rendering rate? If not, I would suggest that you implement that. And if this is only happening in the emulator, I think that the emulator might just be too slow. – AttackingHobo Jun 10 '11 at 21:05
• why would i need a timestep? all my physics calculations are time based.. dont see the point on locking the game at a fixed fps. – jernej Jun 11 '11 at 15:05
• @Jernej if you have a fixed timestep with interpolation you can update at 30 fps, but render at 60 fps(or whatever fps the device can handle) and use interpolation to make it look smooth regardless of the fps. – AttackingHobo Jun 13 '11 at 2:47
• @AttackingHobo i've implemented the interpolation, but the problem with lock_layer still persists, because drawing is done as fast as possible.Not realy sure to ignore it or not. – jernej Jun 13 '11 at 17:56
• Is the rendering taking too long, or the updating taking too long? – AttackingHobo Jun 13 '11 at 18:18

You have implemented a fixed time step with frame-skipping. Any devices that cannot run your game are below the minimum requirements.

You should find some users with older devices to test with, and see exactly how old of a system your game can actually run on. Once you are at that point, see if there is any optimization you can do to improve the speed.

• thanks for your help. decided that until the game doesnt lag on a real device, i'll just ignore the emulator warnings. – jernej Jun 13 '11 at 19:12

The android emulator is much slower than the average modern device.

In a game I was making I easily reached 60fps on my Nx1, but on the emulator I was barely able to reach 15-25fps.

You're correct when you say that this error happens because rendering takes too long, and be warned that you might get the same problem on slower devices, or anyway devices that are running in background many apps while they run yours — so yes, you have to actually solve it.

As @AttackingHobo suggests, you have to implement a system which supports frameskipping.

• what do u mean with frameskipping? I dont want to lock the rendering at a specific timestep. I want to get as many fps on every device as possible. Can u explain how this could be achived. Thanks. – jernej Jun 12 '11 at 13:04
• You're missing the very basics, in that case. You might want to grab a generic tutorial on game programming, I guess any will do (and I'm certain there are many threads about that here). – o0'. Jun 12 '11 at 13:48
• do u mean something like this: obviam.net/index.php/the-android-game-loop – jernej Jun 12 '11 at 14:09
• So i've read all i could find.. also tried to implement interpolation, but the problem with lock_layer is still present! I would like to use the interpolation method, which doesn't locks the renderer at a specific FPS and bypass the lock_layer error. Is that possible? Or am i still missing something? – jernej Jun 13 '11 at 18:10