Skip to content

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

Open
sentry-junior[bot] wants to merge 2 commits into
mainfrom
fix/replay-emulator-software-canvas
Open

sentry-junior[bot] wants to merge 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.

📝 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]

sentry-junior Bot and others added 2 commits October 19, 2026 10:03
… Emulator

Co-Authored-By: Roman Zavarnitsyn <roman.zavarnitsyn@sentry.io>
Co-Authored-By: Roman Zavarnitsyn <roman.zavarnitsyn@sentry.io>
@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

This branch has not been deployed

No deployments
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

0 participants