diff options
| author | JosJuice <josjuice@gmail.com> | 2025-07-27 11:37:45 +0200 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2025-07-27 11:37:45 +0200 |
| commit | 8524e725a8e883a0c763b6d791095aba5ff5e5ab (patch) | |
| tree | 22d13755bea13a1a8e439d7ed54a9086a19f92b3 /Source/Android/app/src/main/java | |
| parent | 1c7df370d9d5b443b5878c38aa03e1a64437309a (diff) | |
Android: Add additional null check in GCAdapter
Just in case, since the documentation says this could be null.
Diffstat (limited to 'Source/Android/app/src/main/java')
| -rw-r--r-- | Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/GCAdapter.java | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/GCAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/GCAdapter.java index 12ed20fec7..b9e67e654f 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/GCAdapter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/GCAdapter.java @@ -142,43 +142,48 @@ public class GCAdapter { dev = adapterDevice; } + if (dev == null) + { + return false; + } - if (dev != null) + usbConnection = manager.openDevice(dev); + if (usbConnection == null) { - usbConnection = manager.openDevice(dev); + return false; + } - Log.info("GCAdapter: Number of configurations: " + dev.getConfigurationCount()); - Log.info("GCAdapter: Number of interfaces: " + dev.getInterfaceCount()); + Log.info("GCAdapter: Number of configurations: " + dev.getConfigurationCount()); + Log.info("GCAdapter: Number of interfaces: " + dev.getInterfaceCount()); - if (dev.getConfigurationCount() > 0 && dev.getInterfaceCount() > 0) - { - UsbConfiguration conf = dev.getConfiguration(0); - usbInterface = conf.getInterface(0); - usbConnection.claimInterface(usbInterface, true); + if (dev.getConfigurationCount() > 0 && dev.getInterfaceCount() > 0) + { + UsbConfiguration conf = dev.getConfiguration(0); + usbInterface = conf.getInterface(0); + usbConnection.claimInterface(usbInterface, true); - Log.info("GCAdapter: Number of endpoints: " + usbInterface.getEndpointCount()); + Log.info("GCAdapter: Number of endpoints: " + usbInterface.getEndpointCount()); - if (usbInterface.getEndpointCount() == 2) - { - for (int i = 0; i < usbInterface.getEndpointCount(); ++i) - if (usbInterface.getEndpoint(i).getDirection() == UsbConstants.USB_DIR_IN) - usbIn = usbInterface.getEndpoint(i); - else - usbOut = usbInterface.getEndpoint(i); - - initAdapter(); - return true; - } - else - { - usbConnection.releaseInterface(usbInterface); - } + if (usbInterface.getEndpointCount() == 2) + { + for (int i = 0; i < usbInterface.getEndpointCount(); ++i) + if (usbInterface.getEndpoint(i).getDirection() == UsbConstants.USB_DIR_IN) + usbIn = usbInterface.getEndpoint(i); + else + usbOut = usbInterface.getEndpoint(i); + + initAdapter(); + return true; + } + else + { + usbConnection.releaseInterface(usbInterface); } - - Toast.makeText(DolphinApplication.getAppContext(), R.string.replug_gc_adapter, - Toast.LENGTH_LONG).show(); - usbConnection.close(); } + + Toast.makeText(DolphinApplication.getAppContext(), R.string.replug_gc_adapter, + Toast.LENGTH_LONG).show(); + usbConnection.close(); return false; } |
