Skip to content

fix(replay): Use software canvas for the video encoder on the Android Emulator - #6282

Merged
romtsn merged 2 commits into
mainfrom
fix/replay-emulator-software-canvas
Oct 21, 2026
Merged

romtsn merged 2 commits into
mainfrom
fix/replay-emulator-software-canvas

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

📜 Description

SimpleVideoEncoder now draws frames with lockCanvas(null) instead of lockHardwareCanvas() when running on the Android Emulator (Build.HARDWARE contains goldfish or ranchu), the same way it already does for Xiaomi, Motorola and Spreadtrum/Unisoc devices. The device check moved into an internal shouldUseSoftwareCanvas() function so it can be unit tested.

💡 Motivation and Context

With a hardware canvas, hwui creates an EGL window surface on the encoder's input Surface. The emulator's EGL driver (libEGL_emulation, gfxstream guest/egl/egl.cpp) dequeues the next buffer up front, at surface init and after every swapBuffers, and cancels it in ~egl_window_surface_t. CCodec::stop() already disconnects the input surface, so when Surface.release() later destroys the hwui context, the driver cancels a buffer whose queue is gone. That shows up as an intermittent SIGSEGV in eglDestroySurface on the RenderThread. A software canvas keeps hwui and EGL off this surface entirely. Drawing one small bitmap per frame on the CPU is cheap.

Reordering the teardown in release() was considered too. It would have to move surface.release() before mediaCodec.stop(), not just before mediaCodec.release(), and it changes behavior on every device. This PR keeps the change scoped to the emulator.

💚 How did you test it?

Added SimpleVideoEncoderCanvasTest, a Robolectric test that covers regular devices, Xiaomi, Motorola, and ranchu/goldfish emulators. ReplayCacheTest still passes. The reporter offered to try a patched build on the emulator image where the crash happened.

Example replay: https://sentry-sdks.sentry.io/replays/c705d79743844792bc9f70e32f76203a/

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

Ask the reporter to verify on system-images;android-37.1;google_apis_playstore_ps16k;arm64-v8a.

via roman.

--

View Junior Session [Sentry]

@romtsn
romtsn marked this pull request as ready for review October 19, 2026 10:20
@sentry

sentry Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.61.0 (1) release

⚙️ sentry-android Build Distribution Settings

@0xadam-brown 0xadam-brown left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

sentry-junior Bot and others added 2 commits October 21, 2026 14:48
… Emulator

Co-Authored-By: Roman Zavarnitsyn <roman.zavarnitsyn@sentry.io>
Co-Authored-By: Roman Zavarnitsyn <roman.zavarnitsyn@sentry.io>

Co-Authored-By: Roman Zavarnitsyn <roman.zavarnitsyn@sentry.io>
@sentry-junior
sentry-junior Bot force-pushed the fix/replay-emulator-software-canvas branch from 986e839 to a85cc01 Compare October 21, 2026 14:54
@romtsn
romtsn merged commit a0ac761 into main Oct 21, 2026
69 of 70 checks passed
@romtsn
romtsn deleted the fix/replay-emulator-software-canvas branch October 21, 2026 16:30
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.

Session Replay: native SIGSEGV in eglDestroySurface (libEGL_emulation) when SimpleVideoEncoder releases its input surface on the Android emulator

2 participants