Skip to content

Commit

Permalink
Apply workarounds only on error
Browse files Browse the repository at this point in the history
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 <#994>
Refs #365 <#365>
Refs #940 <#940>
  • Loading branch information
rom1v committed May 1, 2020
1 parent d4eeb1c commit 62c0c13
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:
// <https://github.com/Genymobile/scrcpy/issues/365>
// <https://github.com/Genymobile/scrcpy/issues/940>
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;
Expand Down

0 comments on commit 62c0c13

Please sign in to comment.