Skip to content

Defer the EAGLDevice background gate until applicationDidEnterBackground.#1460

Merged
Hparty merged 2 commits into
mainfrom
bugfix/thunderllei_appbackground_timing
May 29, 2026
Merged

Defer the EAGLDevice background gate until applicationDidEnterBackground.#1460
Hparty merged 2 commits into
mainfrom
bugfix/thunderllei_appbackground_timing

Conversation

@leiyue123
Copy link
Copy Markdown
Collaborator

之前 iOS 端在 applicationWillResignActive 中就将 appInBackground 置为 true,导致诸如来电、控制中心下拉、分享面板弹出等场景下,app 仍处于前台但渲染已被阻塞(GLDevice::Current()/Make() 直接返回 nullptr),出现画面停滞或闪烁。

本次调整将后台闸门延后到真正进入后台时再关闭:

  • applicationWillResignActive:仅对所有 EAGLDevice 执行 glFinish 冲刷已提交的 GL 命令,避免在 applicationDidEnterBackground 的约 5 秒窗口内执行长时间 glFinish 被系统终止;不再修改 appInBackground,保持前台 GL 调用可用。
  • applicationDidEnterBackground:新增回调,在真正进入后台时关闭闸门(appInBackground = true),符合 Apple 文档对后台执行 OpenGL ES 调用会导致进程被终止的约束。
  • applicationWillEnterForeground:新增回调,在回前台时立即打开闸门。
  • applicationDidBecomeActive:继续作为打开闸门的兜底路径,覆盖冷启动只触发 didBecomeActive 的场景,并继续处理后台期间累积的延迟删除列表。

效果:来电、控制中心、分享面板等短暂离焦但未进入后台的场景下,渲染不再中断;真正进入后台的安全边界与原有一致。

// to leave the GPU in a quiescent state. This avoids doing a long glFinish() inside
// applicationDidEnterBackground:, which has a strict ~5s execution window before iOS terminates
// the process.
std::vector<std::shared_ptr<EAGLDevice>> devices = {};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里要移动就都移动了,不能漏。漏了有可能后续还有新的gl命令

@leiyue123 leiyue123 force-pushed the bugfix/thunderllei_appbackground_timing branch from 07e7130 to af8788b Compare May 29, 2026 09:58
…to avoid GL deletions racing with new draw calls.
@Hparty Hparty merged commit beb0b4e into main May 29, 2026
12 checks passed
@Hparty Hparty deleted the bugfix/thunderllei_appbackground_timing branch May 29, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants