android - Getting ANR when GLThread is very busy and the application is in background
问题描述
I've noticed the following weird behaviour when my GLThread is doing an intensive work.
Launch the application and wait until the GLThread does an intensive task. Send the application to background Send a push notification from firebase Wait until ANR show up (because the application cannot wake up the Notification Service)
If instead of sending the application to background I just wait with the application in foreground, the notification arrives and the ANR does not show up.
In theory GLThread is not the main thread so I should be able to do any kind of work in there without getting an ANR.
You can find my project here: https://issuetracker.google.com/issues/113119768
In order to reproduce my "intensive work" i just put an infinite loop on the onDrawFrame Function
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
while(true)
{
Log.e("GLThread", "draw");
}
}
Any help would be very appreciated.
解决方案
问题是这个无限循环 onDrawFrame() 回调,通过这样的操作,您将锁定 GL 线程。
我想 GL 线程来自 GLSurfaceView 或类似的?您必须了解,您不能在此方法中放置无限循环。onDrawFrame() 函数只是每次表面准备好绘制新帧时由 GL 线程触发的回调。如果您不允许回调继续,那么您将阻塞 GL 线程。
因此,除了不允许工作流继续之外,与 GL 线程通信的其他线程也将被锁定。例如,当 UI 线程告诉 GLSurface 停止时,在这种情况下会导致 ANR,因为 onDrawFrame() 方法由于无限循环而持有当前的 GL 同步锁。
推荐阅读
- python - 从 django 中的自定义数据库表中检查电子邮件和密码
- python - 从python中的数据框中删除\ n
- rpm - 从当前目录中的文件和文件夹创建 rpm
- python - 按日期分离并获取多维数组的最大值 Pandas Python
- replication - Google SQL - 外部只读副本未更新
- reactjs - React with TS can't see any contect inside background wrapper component
- c# - 在“读取共享”模式下以编程方式打开 Excel
- sql - 如何在 MS SQL Server 中的单个字段同时使用拆分、转换、大小写?
- zeromq - ZMQ_SNDHWM 和 ZMQ_RCVHWM 始终设置为默认值
- amazon-web-services - Amazon Personalize 活动分数如何工作