From a5ca8a7472b18bbb9da1918546dafc28f39d6170 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 18 Jun 2016 14:40:42 -0700 Subject: [PATCH] Add a hack to avoid crashing when the app window divider is dragged off of the screen on N multi-window --- app/src/main/java/com/limelight/Game.java | 8 ++++++++ .../binding/video/MediaCodecDecoderRenderer.java | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/limelight/Game.java b/app/src/main/java/com/limelight/Game.java index c40d8f47..485f6cb5 100644 --- a/app/src/main/java/com/limelight/Game.java +++ b/app/src/main/java/com/limelight/Game.java @@ -971,6 +971,14 @@ public class Game extends Activity implements SurfaceHolder.Callback, @Override public void surfaceDestroyed(SurfaceHolder holder) { if (connected) { + // HACK: Android is supposed to let you return from this function + // before throwing a fit if you access the surface again. Unfortunately, + // MediaCodec often tries to access the destroyed surface and triggers + // an IllegalStateException. To workaround this, we will invoke + // the DecoderRenderer's stop function ourselves, so it will hopefully + // happen early enough to not trigger the bug + decoderRenderer.stop(); + stopConnection(); } } diff --git a/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java b/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java index c2dfab45..b38b24c8 100644 --- a/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java +++ b/app/src/main/java/com/limelight/binding/video/MediaCodecDecoderRenderer.java @@ -475,8 +475,8 @@ public class MediaCodecDecoderRenderer extends EnhancedDecoderRenderer { } catch (InterruptedException ignored) { } } - // Stop the decoder - videoDecoder.stop(); + // We could stop the decoder here, but it seems to cause some problems + // so we'll just let release take care of it. } @Override