From f5a3aac8e1ef77c3f1c1e30f47e15222752a538b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Mon, 6 Feb 2017 22:09:43 +0100 Subject: [PATCH] IOS: Check if libusb can be used instead of asserting This prevents panic alerts from showing up three times when starting Wii emulation whenever libusb could not be initialized. The user has already seen a warning at startup -- no need to warn them 3 more times. --- Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp | 5 +- Source/Core/Core/IOS/USB/Host.cpp | 50 ++++++++++--------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp b/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp index 0e7267b614..72d536fd3a 100644 --- a/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp +++ b/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp @@ -61,8 +61,6 @@ BluetoothReal::BluetoothReal(u32 device_id, const std::string& device_name) : BluetoothBase(device_id, device_name) { m_libusb_context = LibusbContext::Get(); - _assert_msg_(IOS_WIIMOTE, m_libusb_context, "Failed to init libusb."); - LoadLinkKeys(); } @@ -84,6 +82,9 @@ BluetoothReal::~BluetoothReal() ReturnCode BluetoothReal::Open(const OpenRequest& request) { + if (!m_libusb_context) + return IPC_EACCES; + libusb_device** list; const ssize_t cnt = libusb_get_device_list(m_libusb_context.get(), &list); _dbg_assert_msg_(IOS, cnt > 0, "Couldn't get device list"); diff --git a/Source/Core/Core/IOS/USB/Host.cpp b/Source/Core/Core/IOS/USB/Host.cpp index 875dc451f1..80c19e34fa 100644 --- a/Source/Core/Core/IOS/USB/Host.cpp +++ b/Source/Core/Core/IOS/USB/Host.cpp @@ -32,7 +32,6 @@ USBHost::USBHost(u32 device_id, const std::string& device_name) : Device(device_ { #ifdef __LIBUSB__ m_libusb_context = LibusbContext::Get(); - _assert_msg_(IOS_USB, m_libusb_context, "Failed to init libusb."); #endif } @@ -117,31 +116,36 @@ bool USBHost::AddNewDevices(std::set& new_devices, DeviceChangeHooks& hooks const bool always_add_hooks) { #ifdef __LIBUSB__ - libusb_device** list; - const ssize_t count = libusb_get_device_list(m_libusb_context.get(), &list); - if (count < 0) + if (m_libusb_context) { - WARN_LOG(IOS_USB, "Failed to get device list: %s", libusb_error_name(static_cast(count))); - return false; - } + libusb_device** list; + const ssize_t count = libusb_get_device_list(m_libusb_context.get(), &list); + if (count < 0) + { + WARN_LOG(IOS_USB, "Failed to get device list: %s", + libusb_error_name(static_cast(count))); + return false; + } - for (ssize_t i = 0; i < count; ++i) - { - libusb_device* device = list[i]; - libusb_device_descriptor descriptor; - libusb_get_device_descriptor(device, &descriptor); - if (!SConfig::GetInstance().IsUSBDeviceWhitelisted({descriptor.idVendor, descriptor.idProduct})) - continue; + for (ssize_t i = 0; i < count; ++i) + { + libusb_device* device = list[i]; + libusb_device_descriptor descriptor; + libusb_get_device_descriptor(device, &descriptor); + if (!SConfig::GetInstance().IsUSBDeviceWhitelisted( + {descriptor.idVendor, descriptor.idProduct})) + continue; - auto usb_device = std::make_unique(device, descriptor); - if (!ShouldAddDevice(*usb_device)) - continue; - const u64 id = usb_device->GetId(); - new_devices.insert(id); - if (AddDevice(std::move(usb_device)) || always_add_hooks) - hooks.emplace(GetDeviceById(id), ChangeEvent::Inserted); + auto usb_device = std::make_unique(device, descriptor); + if (!ShouldAddDevice(*usb_device)) + continue; + const u64 id = usb_device->GetId(); + new_devices.insert(id); + if (AddDevice(std::move(usb_device)) || always_add_hooks) + hooks.emplace(GetDeviceById(id), ChangeEvent::Inserted); + } + libusb_free_device_list(list, 1); } - libusb_free_device_list(list, 1); #endif return true; } @@ -195,7 +199,7 @@ void USBHost::StartThreads() } #ifdef __LIBUSB__ - if (!m_event_thread_running.IsSet()) + if (m_libusb_context && !m_event_thread_running.IsSet()) { m_event_thread_running.Set(); m_event_thread = std::thread([this] {