Repository navigation
fix(android): restore Skia content after activity recreation - #24586
morning4coffe-dev wants to merge 1 commit into
Conversation
|
Claude finished @morning4coffe-dev's task in 4m 29s —— View job Review complete
Verdict: fix-first — the core fix is sound; one plausible correctness issue posted inline, plus cross-cutting notes below. Findings by severity: 1 medium (plausible), 0 confirmed blockers. What I verified as correct (root-cause, not just guard)
Inline finding
Cross-cutting, non-blocking
|
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Renderer-generation synchronization is needed to prevent stale frames from releasing the first-frame gate.
Review effort: Lite
Findings: None
What changed in this PR
Restores retained Skia content after Android Activity recreation by fixing lifecycle ordering, renderer state reset, and configuration-change handling.
Changes:
- Initializes layout services before retained-content reattachment.
- Resets Canvas and Vulkan first-frame state.
- Preserves the managed window during configuration changes.
| File | Summary |
|---|---|
src/Uno.UI.Runtime.Skia.Android/Rendering/UnoSKVulkanView.cs |
Resets Vulkan first-frame state across recreation. |
src/Uno.UI.Runtime.Skia.Android/Rendering/UnoSKCanvasView.cs |
Resets Canvas renderer and first-frame state. |
src/Uno.UI.Runtime.Skia.Android/ApplicationActivity.cs |
Corrects Activity recreation ordering and lifecycle handling. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24586/wasm-skia-net9/index.html |
|
Claude finished @morning4coffe-dev's task in 4m 3s —— View job Review complete
Verdict: fix-first — the newest commit ( Findings by severity: 1 plausible correctness issue (the Cross-cutting, non-blocking
|
| public void ResetRendererContext() | ||
| { | ||
| _renderer.ResetContext(); | ||
| _renderer.ResetFirstFrameState(); | ||
| QueueEvent(_renderer.ResetContext); | ||
| } |
There was a problem hiding this comment.
Plausible: the GL-thread hop lands while the view is detached, so FreeContext() is silently dropped
This addresses the earlier cross-thread race by moving ResetContext onto the GL thread via QueueEvent, but the only caller (ApplicationActivity.InitializeComponent, line 129) invokes it after parent.RemoveView(RelativeLayout) (line 125) has detached the retained GLSurfaceView and before SetContentView(RelativeLayout) (line 131) reattaches it.
GLSurfaceView.onDetachedFromWindow() synchronously calls mGLThread.requestExitAndWait(), which tears down the EGL context/surface and exits the render-thread loop. A new GLThread is only created later, in onAttachedToWindow() (triggered by the SetContentView reattach). GLSurfaceView.queueEvent(...) delegates directly to the current mGLThread instance — at the point this is called, that's the old, already-exited thread. The runnable is enqueued but that thread's loop has already returned, so it never runs: FreeContext() never executes.
Net effect: _context, _renderTarget, _glBackedSurface stay non-null after "reset," still referencing GL objects created against the now-destroyed EGL context. When the new GL thread starts, OnDrawFrame's if (_context == null) guard is false, so it reuses the stale GRContext/surfaces from a different EGL context on a different thread instead of recreating them — which looks like it reproduces the exact "explicit Activity.Recreate(): stale/crashing retained-view lifecycle" symptom this PR is meant to fix, just moved one step later in the sequence.
Consider either queuing the reset from onAttachedToWindow (after reattachment, when the new GL thread is guaranteed to exist), or nulling _context/_renderTarget/_glBackedSurface/_softwareSurface synchronously here and letting OnDrawFrame's existing null-check lazily recreate them on whichever GL thread ends up running — avoiding the cross-thread dispose without depending on a stale thread reference.
| internal void ResetContext() | ||
| { | ||
| FreeContext(); | ||
| } |
There was a problem hiding this comment.
Minor style nit: ResetContext() is a one-line delegation and per the repo's code style guidance should stay expression-bodied (as it was before this diff) rather than a block body:
| } | |
| internal void ResetContext() => FreeContext(); |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24586/wasm-skia-net9/index.html |
|
The build 234952 found UI Test snapshots differences: Details
|
Initialize the new Activity's LayoutProvider before retained Skia content is reattached, re-arm the first-frame gate, and treat configuration-driven Activity destruction as transient instead of closing the Uno window. Release the retained GRContext when the new EGL context is created: the GLSurfaceView render thread exits on detach, so work queued to it before reattachment never runs. The context is abandoned first so Skia issues no deletes for old GL object names into the new context.
d889605 to
c53f2e7
Compare
|
Claude finished @morning4coffe-dev's task in 3m 9s —— View job Review complete
Verdict: ship — the latest commit resolves both previously-flagged correctness issues; no new blocking findings. Findings by severity: 0 new issues (2 prior plausible issues confirmed resolved, 1 prior style nit confirmed resolved). What changed since the last review pass and why it's now correct
Cross-cutting, non-blocking (repeated from prior passes)
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24586/wasm-skia-net9/index.html |
|
The build 235384 found UI Test snapshots differences: Details
|
OnDestroy raised the native close for every Activity destruction, so a configuration-driven recreation (rotation, density change, Recreate) closed the Uno window even though its content is carried over to the new Activity. Ported from #24586. Co-Authored-By: morning4coffe-dev <[email protected]> Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01GwbrDBytd9CFt9aZoV8s1o
|
Thanks @morning4coffe-dev! This one and #24599 fix the same two bugs from different angles: the first-frame gate is never released after the Activity is recreated, and the
Closing in favor of #24599. |
Summary
LayoutProviderbefore retained Skia content can be synchronously reattached;GLSurfaceViewrender thread;Broken invariant
ApplicationActivityretains its managed window and Android render view across Activity replacement. The previous order could reattach retained content before the new Activity had initialized layout services, while the renderer retained its prior context and first-frame state. Configuration recreation also raised permanent native-window close.Stock
7.0.0-dev.763reproduced:Activity.Recreate(): stale/crashing retained-view lifecycle.Validation
Compile
10.0.111Uno.UI.Runtime.Skia.Android.csprojnet10.0-androidRuntime
Fresh API 36 x64 emulator, explicit
emulator-5580, non-incremental install:mastersource app reached a visible, interactive first frame;Activity.Recreate()cycles completed in the same process;GLThreadwith noUnoVulkanRenderthread;The same emulator also proved the unchanged packaged Uno 7 control fails same-process relaunch with a black surface, preserving a stock failing control.
Scope
This fixes the Uno Android Skia host lifecycle. It does not claim MAUI compatibility, broad device coverage, AOT qualification, or general Android application acceptance.