Skip to content

tests: Add device test proving SKGLView renders after reattach (validates #3076)#3554

Open
mattleibow wants to merge 1 commit intomainfrom
dev/issue-2550-skglview-android-reattach-fix
Open

tests: Add device test proving SKGLView renders after reattach (validates #3076)#3554
mattleibow wants to merge 1 commit intomainfrom
dev/issue-2550-skglview-android-reattach-fix

Conversation

@mattleibow
Copy link
Contributor

@mattleibow mattleibow commented Mar 10, 2026

Summary

This PR adds an Android device test that proves the fix in PR #3076 works:

  • Without the fix: test fails with got 0x0
  • With the fix: test passes

The fix itself lives in #3076 (by @SimonvBez). This PR contains only the test.

Test: GLThreadHasCorrectDimensionsAfterReattach

File: tests/SkiaSharp.Tests.Devices/Tests/Maui/SKGLViewTests.cs

The Bug (issue #2550)

When SKGLView is placed on a MAUI TabBar tab, switching away and back causes it to stop rendering. Root cause:

OnAttachedToWindow() creates new GLThread(weakRef) with width=0, height=0. Because the view's bounds haven't changed, Android never fires OnLayoutChange again — so GLThread.OnWindowResize() is never called. IsReadyToDraw() keeps returning false (requires width > 0 && height > 0), so the view never renders.

How the test works

  1. Attaches the view and waits for first render (precondition)
  2. Uses native Android RemoveView()/AddView() to detach and reattach — bypassing MAUI's handler lifecycle (which would recreate the view)
  3. Reads GLThread.width/height via reflection immediately after AddView() — before any async OnLayoutChange callback can supply dimensions
  4. Asserts dimensions are > 0

This captures the raw state OnAttachedToWindow() sets, which is exactly the window where the bug lives in the real tab-bar scenario.

Before/After Results (on emulator-5554)

Without fix (#3076 not applied):

⛔ GLThread dimensions should be positive immediately after OnAttachedToWindow, got 0x0.
   Expected: True
   Actual:   False

With fix (#3076 applied):

✔ Success! 1606.2943 ms

Related

@mattleibow mattleibow force-pushed the dev/issue-2550-skglview-android-reattach-fix branch 2 times, most recently from fbfbfe0 to d059c71 Compare March 10, 2026 12:12
@mattleibow mattleibow changed the title Fix SKGLView on Android not rendering after tab switch (issue #2550) tests: Add device test proving SKGLView renders after reattach (validates #3076) Mar 10, 2026
Adds SKGLViewTests.GLThreadHasCorrectDimensionsAfterReattach, an Android
device test that validates the fix in PR #3076.

The test exercises the exact failure mode:
- Uses native Android RemoveView/AddView to detach/reattach the GL view
  without triggering MAUI's handler lifecycle (which would recreate the view)
- Reads GLThread.width/height via reflection immediately after AddView(),
  before any async OnLayoutChange callback can supply dimensions

WITHOUT the fix (PR #3076): GLThread starts with width=0, height=0 → FAIL
  ⛔ "GLThread dimensions should be positive immediately after OnAttachedToWindow, got 0x0"

WITH the fix (PR #3076): GLThread starts with correct dimensions → PASS
  ✔ Success! ~1600ms

Relates to #2550. Test validates fix in #3076.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mattleibow mattleibow force-pushed the dev/issue-2550-skglview-android-reattach-fix branch from d059c71 to 04e413e Compare March 10, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[BUG] SKGLView doesn't repaint if it's in a TabBar [BUG] SKGLView don't redraw after return from other page on Android In Maui

1 participant