fix(video-grid): scope forced bind to on-screen page to avoid EGL context exhaustion - #803
Open
sapta100ms wants to merge 2 commits into
Open
fix(video-grid): scope forced bind to on-screen page to avoid EGL context exhaustion#803sapta100ms wants to merge 2 commits into
sapta100ms wants to merge 2 commits into
Conversation
sapta100ms
force-pushed
the
fix/videogrid-egl-context-exhaustion
branch
from
August 17, 2026 07:13
5335370 to
a750552
Compare
… context exhaustion RoomKit 1.3.10 changed the video-grid speaker/track observers to always bind (isForceUpdate=true), so off-screen pager pages (offscreenPageLimit=1 keeps 3 alive) also created a SurfaceViewRenderer + EGL context each. That roughly tripled the live EGL contexts; in large rooms on low/mid-end GPUs (which cap contexts, commonly ~32) the next tile's eglCreateContext fails and the app crashes with 'Failed to create EGL context'. Scope the forced bind to the page actually on screen (isSelectedPage()) instead of forcing it on every live page. The visible page still force-binds, so the SFU-migration recreate race the flag was added for is still handled; off-screen pages bind lazily via onResume -> bindViews() when swiped to. - VideoGridFragment: track the selected page per pager via OnPageChangeCallback. - VideoGridPageFragment: isForceUpdate = isSelectedPage() on both observers. - VideoGridBaseFragment: always release a removed tile's renderer (drop the visibility gate) so scoping the bind can't orphan a live EGL context. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
sapta100ms
force-pushed
the
fix/videogrid-egl-context-exhaustion
branch
from
August 17, 2026 07:40
a750552 to
2076ff6
Compare
…ilds When the video-grid page count shrinks (e.g. SFU migration drops pages to 0 then rebuilds), ViewPager2 clamps currentItem to 0 but does not reliably dispatch onPageSelected(0). That left currentPeerGridPage/currentScreenSharePage stale, so the visible page-0 evaluated isSelectedPage()==false and skipped the force-bind — reintroducing the transient black tile on the visible page after a migration. Mirror the clamp: reset the tracker to 0 when the new page count makes the tracked index out of range. A simple grow (e.g. 3->4 pages) does not clamp, so the tracker is preserved. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Crash on the video grid:
RuntimeException: android.opengl.GLException: Failed to create EGL context(fromSurfaceViewRenderer.init→HMSVideoView.addTrack). High volume for large-room customers on low/mid-end GPUs (e.g. Entri).Cause
Each video tile allocates its own EGL context (a capped GPU resource — commonly ~32 on low-end GPUs). RoomKit 1.3.10 changed the grid observers to bind unconditionally (
isForceUpdate = true). WithoffscreenPageLimit = 1, three pager pages are alive, so the off-screen pages started creating contexts too — ~3× the live contexts. In large rooms this crosses the device cap and the nexteglCreateContextfails → crash. (Latent before 1.3.10; the change amplified it.)isForceUpdate = truewas added to fix black tiles after an SFU migration (fragment recreated, LiveData delivers beforeonResume, bind gated out). That only ever mattered for the on-screen page.Fix
Scope the forced bind to the page actually on screen, so off-screen pages no longer hold contexts (they bind lazily on
onResumewhen swiped to). Live contexts drop back to ~1 page's worth (pre-1.3.10 baseline); the migration fix is preserved for the visible page.ViewPager2.OnPageChangeCallback.isForceUpdate = isSelectedPage()on both the speaker and screenshare observers.Testing
:room-kit:compileDebugKotlinpasses.GLExceptionand video still renders on the visible page.Note
SFU migration is not enabled on Android yet; when it is, verify the visible grid page re-renders after a migration (the scoped force still covers it).
🤖 Generated with Claude Code