最近原来的游戏趋于稳定,一些小问题慢慢被玩家提及越来越多。图片显示异常的问题很早就有,但是极少出现,最近抽空重点检查了一下。总算搞定了,特别记录一下。
通过一直以来玩家反馈的数据,我找了一下规律,错误都是弹出框,并且大部分都是游戏的消息框。还有一个共性就是所有的错误都是在异步线程中引发的。比较奇怪的是在lwjgl中是直接报错,但是在android中是图片显示异常。最后总算捕获到该异常:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
com.badlogic.gdx.utils.GdxRuntimeException: java.lang.RuntimeException: No OpenGL context found
in
the current thread.
at com.badlogic.gdx.assets.AssetManager.handleTaskError(AssetManager.java:
471
)
at com.badlogic.gdx.assets.AssetManager.update(AssetManager.java:
316
)
at com.dreamoe.pirateage.client.ApkAssets.loading(ApkAssets.java:
82
)
at com.dreamoe.pirateage.client.ApkAssets.
get
(ApkAssets.java:
54
)
at com.dreamoe.pirateage.client.Assets.
get
(Assets.java:
229
)
at com.dreamoe.pirateage.client.actor.impl.window.TipWindow.<init>(TipWindow.java:
30
)
at com.dreamoe.pirateage.client.actor.impl.window.TipWindow.show(TipWindow.java:
48
)
at com.dreamoe.pirateage.client.aop.RemoteAspect.invoke(RemoteAspect.java:
86
)
at $Proxy0.registerUser(Unknown Source)
at com.dreamoe.pirateage.client.manager.remote.Remote.registerUser(Remote.java:
1248
)
at com.dreamoe.pirateage.client.actor.impl.window.RegisterWindow$
1
$
1
.doInRegisterWindow.java:
187
)
at com.dreamoe.pirateage.client.thread.AsyncWaitThread.run(AsyncWaitThread.java:
29
)
Caused by: java.lang.RuntimeException: No OpenGL context found
in
the current thread.
at org.lwjgl.opengl.GLContext.getCapabilities(GLContext.java:
124
)
at org.lwjgl.opengl.GL11.glGenTextures(GL11.java:
1468
)
at com.badlogic.gdx.backends.lwjgl.LwjglGL10.glGenTextures(LwjglGL10.java:
240
)
at com.badlogic.gdx.graphics.Texture.createGLHandle(Texture.java:
166
)
at com.badlogic.gdx.graphics.Texture.create(Texture.java:
158
)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:
154
)
at com.badlogic.gdx.assets.loaders.TextureLoader.loadSync(TextureLoader.java:
84
)
at com.badlogic.gdx.assets.loaders.TextureLoader.loadSync(TextureLoader.java:
1
)
at com.badlogic.gdx.assets.AssetLoadingTask.handleAsyncLoader(AssetLoadingTask.java:
130
)
at com.badlogic.gdx.assets.AssetLoadingTask.update(AssetLoadingTask.java:
94
)
at com.badlogic.gdx.assets.AssetManager.updateTask(AssetManager.java:
399
)
at com.badlogic.gdx.assets.AssetManager.update(AssetManager.java:
314
)
...
10
more
|
通过不断模拟假设并验证,最后发现我写了一个异步线程去做服务器交互,主界面锁定等待。当在这个异步线程中做了assetManager.loading的动作去加载新的图片,这其实就不是在主线程做的,因而导致图片加载异常。由于程序中图片有缓存,所以才导致只有加载一次图片资源就不会出错。结果这个缓存搞的现象变得更难识别。
其实本身还是一个很简单的问题,还是找到重现不走,再分析清楚。
本文转自passover 51CTO博客,原文链接:http://blog.51cto.com/passover/1215093,如需转载请自行联系原作者