问题描述
测试较慢的设备(橙色旧金山又名中兴刀片)对我的比赛,我已经获得了令人震惊的帧速率。
Testing my game on a slower device (Orange San Francisco aka ZTE Blade) and I have been getting an appalling frame rate.
我把一些调试code进入抽奖环路,发现以下行接管100ms的:
I put some debug code into the draw loop and discovered the following line is taking over 100ms:
c = mSurfaceHolder.lockCanvas();
其他人看到这种行为?我通过扩展查看和执行的OnDraw()暂时取代了surfaceview,我得到了一个的多的更好的帧率。
虽然一般surfaceView是我的HTC Desire快得多。我怀疑这可能是Android 2.1的问题。我考虑生根的手机,并将其升级到2.2如果可能的话,但我希望在设备上运行2.1,这样可能会适得其反,从长远来看。
Although in general surfaceView is much faster on my HTC Desire. I am suspicious this may be a Android 2.1 problem. I'm contemplating rooting the phone and upgrading it to 2.2 if possible, but I did want a device running on 2.1 so that might be counter-productive in the long run.
**更新**
我一直对这个多一些,并且已经发现了一些更令人费解的方面吧。
I've been working on this some more, and have discovered some more puzzling aspects to it.
我根深蒂固的手机并安装2.2和问题仍然发生。当第一次启动应用程序时,lockCanvas工作正常(0-1毫秒)。然后,在我的初始化过程中的某个时刻,lockCanvas突然开始服用大约100毫秒。
I rooted the phone and installed 2.2 and the problem still happens. When the app is first started, the lockCanvas is working as expected (0-1 ms). Then at some point during my initialisation, lockCanvas suddenly starts taking approx 100ms.
这可能是值得指出的是,我加载我的资产在一个异步任务,这样我可以显示加载屏幕。
It might be worth pointing out that I am loading my assets in an Async task, so that I can display a loading screen.
尽管牵制什么程序实际上做的时候缓慢occurrs我不能这样做,我尽了最大努力。在当我在调试模式和单步运行其实,它的工作速度快!
Despite my best efforts to pin down what the program is actually doing when the slowness occurrs I was not able to do so. In fact when I run it in debug mode and single step, it works fast!
现在我发现,如果我在SurfaceView(约10秒)的构造函数中添加一个延迟,缓慢不会发生,一切工作正常。
Now I discovered that if I add a delay in the constructor of my SurfaceView (of about 10 seconds), the slowness doesn't occur and all works fine.
不过,如果你preSS主页,然后再切换回来,时差回来。
However if you press Home, and then switch back, the slowness comes back.
我是pretty的多少在我系绳在这种愚蠢的不合逻辑问题的结束!我有一个主意把它归结为一个设备特定问题。
I'm pretty much at the end of my tether on this stupid illogical problem! I've got a mind to put it down to a device specific problem.
我觉得这可能是与内存使用情况。或许真的是被交换出去,这会影响视频RAM?
I feel it could have something to do with memory usage. Maybe something is being swapped out and it affects the video ram?
我想至少有兴趣的理论。
I'd be interested in theories at least.
推荐答案
关于lockCanvas():
About lockCanvas() from docs:
如果您反复在调用此 表面还没有准备好(前 Callback.surfaceCreated或之后 Callback.surfaceDestroyed),您的电话 将被节流以低速率在 为了避免消耗CPU。
难道你平局循环开始得太早了一些设备?我觉得这是问题,因为你写的:
Is it possible that your draw loop is initiated too early for some devices? I think this is the problem, since you wrote:
现在我发现,如果我添加了一个延迟 在我的SurfaceView的构造 (大约10秒),缓慢 不会发生,一切工作正常。
这篇关于lockCanvas()很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!