Skip to content

Commit 62c0c13

Browse files
committed
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 <#994> Refs #365 <#365> Refs #940 <#940>
1 parent d4eeb1c commit 62c0c13

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,20 @@ public boolean consumeRotationChange() {
4747

4848
public void streamScreen(Device device, FileDescriptor fd) throws IOException {
4949
Workarounds.prepareMainLooper();
50-
Workarounds.fillAppInfo();
5150

51+
try {
52+
internalStreamScreen(device, fd);
53+
} catch (NullPointerException e) {
54+
// Retry with workarounds enabled:
55+
// <https://github.com/Genymobile/scrcpy/issues/365>
56+
// <https://github.com/Genymobile/scrcpy/issues/940>
57+
Ln.d("Applying workarounds to avoid NullPointerException");
58+
Workarounds.fillAppInfo();
59+
internalStreamScreen(device, fd);
60+
}
61+
}
62+
63+
private void internalStreamScreen(Device device, FileDescriptor fd) throws IOException {
5264
MediaFormat format = createFormat(bitRate, maxFps, DEFAULT_I_FRAME_INTERVAL);
5365
device.setRotationListener(this);
5466
boolean alive;

0 commit comments

Comments
 (0)