From 62c0c1321feec0a673329cb6771efeefb6dc9657 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 30 Apr 2020 18:37:08 +0200 Subject: [PATCH] Apply workarounds only on error To avoid NullPointerException on some devices, workarounds have been implemented. But these workaround produce (harmless) internal errors causing exceptions to be printed in the console. To avoid this problem, apply the workarounds only if it fails without them. Fixes #994 Refs #365 Refs #940 --- .../java/com/genymobile/scrcpy/ScreenEncoder.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java b/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java index fc1a25b125..2377ec02dd 100644 --- a/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java +++ b/server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java @@ -47,8 +47,20 @@ public boolean consumeRotationChange() { public void streamScreen(Device device, FileDescriptor fd) throws IOException { Workarounds.prepareMainLooper(); - Workarounds.fillAppInfo(); + try { + internalStreamScreen(device, fd); + } catch (NullPointerException e) { + // Retry with workarounds enabled: + // + // + Ln.d("Applying workarounds to avoid NullPointerException"); + Workarounds.fillAppInfo(); + internalStreamScreen(device, fd); + } + } + + private void internalStreamScreen(Device device, FileDescriptor fd) throws IOException { MediaFormat format = createFormat(bitRate, maxFps, DEFAULT_I_FRAME_INTERVAL); device.setRotationListener(this); boolean alive;