GCAdapter: Defer initialization until MainWindow::InitControllers
If libusb fails to initialize, an assertion fails, but if that happens before the main window is created, then Dolphin just dies. Now, the panic alert is properly shown and the user can ignore it.
This commit is contained in:
parent
58c02e6b85
commit
37806472e1
|
@ -521,6 +521,7 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Initialize(J
|
||||||
Common::AndroidSetReportHandler(&ReportSend);
|
Common::AndroidSetReportHandler(&ReportSend);
|
||||||
DolphinAnalytics::AndroidSetGetValFunc(&GetAnalyticValue);
|
DolphinAnalytics::AndroidSetGetValFunc(&GetAnalyticValue);
|
||||||
UICommon::Init();
|
UICommon::Init();
|
||||||
|
GCAdapter::Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ReportStartToAnalytics(JNIEnv*,
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ReportStartToAnalytics(JNIEnv*,
|
||||||
|
|
|
@ -30,6 +30,8 @@
|
||||||
#endif
|
#endif
|
||||||
#include "UICommon/UICommon.h"
|
#include "UICommon/UICommon.h"
|
||||||
|
|
||||||
|
#include "InputCommon/GCAdapter.h"
|
||||||
|
|
||||||
#include "VideoCommon/RenderBase.h"
|
#include "VideoCommon/RenderBase.h"
|
||||||
#include "VideoCommon/VideoBackendBase.h"
|
#include "VideoCommon/VideoBackendBase.h"
|
||||||
|
|
||||||
|
@ -226,6 +228,7 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
UICommon::SetUserDirectory(user_directory);
|
UICommon::SetUserDirectory(user_directory);
|
||||||
UICommon::Init();
|
UICommon::Init();
|
||||||
|
GCAdapter::Init();
|
||||||
|
|
||||||
s_platform = GetPlatform(options);
|
s_platform = GetPlatform(options);
|
||||||
if (!s_platform || !s_platform->Init())
|
if (!s_platform || !s_platform->Init())
|
||||||
|
|
|
@ -113,6 +113,7 @@
|
||||||
#include "DolphinQt/WiiUpdate.h"
|
#include "DolphinQt/WiiUpdate.h"
|
||||||
|
|
||||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||||
|
#include "InputCommon/GCAdapter.h"
|
||||||
|
|
||||||
#include "UICommon/DiscordPresence.h"
|
#include "UICommon/DiscordPresence.h"
|
||||||
#include "UICommon/GameFile.h"
|
#include "UICommon/GameFile.h"
|
||||||
|
@ -328,6 +329,7 @@ void MainWindow::InitControllers()
|
||||||
"No default device has been added in time. EmulatedController(s) defaulting adds"
|
"No default device has been added in time. EmulatedController(s) defaulting adds"
|
||||||
" input mappings made for a specific default device depending on the platform");
|
" input mappings made for a specific default device depending on the platform");
|
||||||
}
|
}
|
||||||
|
GCAdapter::Init();
|
||||||
Pad::Initialize();
|
Pad::Initialize();
|
||||||
Pad::InitializeGBA();
|
Pad::InitializeGBA();
|
||||||
Keyboard::Initialize();
|
Keyboard::Initialize();
|
||||||
|
|
|
@ -75,7 +75,7 @@ static bool s_libusb_hotplug_enabled = false;
|
||||||
static libusb_hotplug_callback_handle s_hotplug_handle;
|
static libusb_hotplug_callback_handle s_hotplug_handle;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static LibusbUtils::Context s_libusb_context;
|
static std::unique_ptr<LibusbUtils::Context> s_libusb_context;
|
||||||
|
|
||||||
static u8 s_endpoint_in = 0;
|
static u8 s_endpoint_in = 0;
|
||||||
static u8 s_endpoint_out = 0;
|
static u8 s_endpoint_out = 0;
|
||||||
|
@ -172,7 +172,7 @@ static void ScanThreadFunc()
|
||||||
if (s_libusb_hotplug_enabled)
|
if (s_libusb_hotplug_enabled)
|
||||||
{
|
{
|
||||||
if (libusb_hotplug_register_callback(
|
if (libusb_hotplug_register_callback(
|
||||||
s_libusb_context,
|
*s_libusb_context,
|
||||||
(libusb_hotplug_event)(LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED |
|
(libusb_hotplug_event)(LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED |
|
||||||
LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT),
|
LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT),
|
||||||
LIBUSB_HOTPLUG_ENUMERATE, 0x057e, 0x0337, LIBUSB_HOTPLUG_MATCH_ANY, HotplugCallback,
|
LIBUSB_HOTPLUG_ENUMERATE, 0x057e, 0x0337, LIBUSB_HOTPLUG_MATCH_ANY, HotplugCallback,
|
||||||
|
@ -218,6 +218,8 @@ void Init()
|
||||||
if (s_handle != nullptr)
|
if (s_handle != nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
s_libusb_context = std::make_unique<LibusbUtils::Context>();
|
||||||
|
|
||||||
if (Core::GetState() != Core::State::Uninitialized && Core::GetState() != Core::State::Starting)
|
if (Core::GetState() != Core::State::Uninitialized && Core::GetState() != Core::State::Starting)
|
||||||
{
|
{
|
||||||
if ((CoreTiming::GetTicks() - s_last_init) < SystemTimers::GetTicksPerSecond())
|
if ((CoreTiming::GetTicks() - s_last_init) < SystemTimers::GetTicksPerSecond())
|
||||||
|
@ -240,7 +242,7 @@ void StartScanThread()
|
||||||
{
|
{
|
||||||
if (s_adapter_detect_thread_running.IsSet())
|
if (s_adapter_detect_thread_running.IsSet())
|
||||||
return;
|
return;
|
||||||
if (!s_libusb_context.IsValid())
|
if (!s_libusb_context->IsValid())
|
||||||
return;
|
return;
|
||||||
s_adapter_detect_thread_running.Set(true);
|
s_adapter_detect_thread_running.Set(true);
|
||||||
s_adapter_detect_thread = std::thread(ScanThreadFunc);
|
s_adapter_detect_thread = std::thread(ScanThreadFunc);
|
||||||
|
@ -266,7 +268,7 @@ static void Setup()
|
||||||
s_controller_type.fill(ControllerTypes::CONTROLLER_NONE);
|
s_controller_type.fill(ControllerTypes::CONTROLLER_NONE);
|
||||||
s_controller_rumble.fill(0);
|
s_controller_rumble.fill(0);
|
||||||
|
|
||||||
s_libusb_context.GetDeviceList([](libusb_device* device) {
|
s_libusb_context->GetDeviceList([](libusb_device* device) {
|
||||||
if (CheckDeviceAccess(device))
|
if (CheckDeviceAccess(device))
|
||||||
{
|
{
|
||||||
// Only connect to a single adapter in case the user has multiple connected
|
// Only connect to a single adapter in case the user has multiple connected
|
||||||
|
@ -397,9 +399,10 @@ void Shutdown()
|
||||||
{
|
{
|
||||||
StopScanThread();
|
StopScanThread();
|
||||||
#if defined(LIBUSB_API_VERSION) && LIBUSB_API_VERSION >= 0x01000102
|
#if defined(LIBUSB_API_VERSION) && LIBUSB_API_VERSION >= 0x01000102
|
||||||
if (s_libusb_context.IsValid() && s_libusb_hotplug_enabled)
|
if (s_libusb_context->IsValid() && s_libusb_hotplug_enabled)
|
||||||
libusb_hotplug_deregister_callback(s_libusb_context, s_hotplug_handle);
|
libusb_hotplug_deregister_callback(*s_libusb_context, s_hotplug_handle);
|
||||||
#endif
|
#endif
|
||||||
|
s_libusb_context.reset();
|
||||||
Reset();
|
Reset();
|
||||||
|
|
||||||
s_status = NO_ADAPTER_DETECTED;
|
s_status = NO_ADAPTER_DETECTED;
|
||||||
|
|
|
@ -108,7 +108,6 @@ void Init()
|
||||||
SConfig::Init();
|
SConfig::Init();
|
||||||
Discord::Init();
|
Discord::Init();
|
||||||
Common::Log::LogManager::Init();
|
Common::Log::LogManager::Init();
|
||||||
GCAdapter::Init();
|
|
||||||
VideoBackendBase::ActivateBackend(Config::Get(Config::MAIN_GFX_BACKEND));
|
VideoBackendBase::ActivateBackend(Config::Get(Config::MAIN_GFX_BACKEND));
|
||||||
|
|
||||||
Common::SetEnableAlert(Config::Get(Config::MAIN_USE_PANIC_HANDLERS));
|
Common::SetEnableAlert(Config::Get(Config::MAIN_USE_PANIC_HANDLERS));
|
||||||
|
|
Loading…
Reference in New Issue