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:
Pokechu22 2022-03-08 13:16:54 -08:00
parent 58c02e6b85
commit 37806472e1
5 changed files with 15 additions and 7 deletions

View File

@ -521,6 +521,7 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Initialize(J
Common::AndroidSetReportHandler(&ReportSend);
DolphinAnalytics::AndroidSetGetValFunc(&GetAnalyticValue);
UICommon::Init();
GCAdapter::Init();
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ReportStartToAnalytics(JNIEnv*,

View File

@ -30,6 +30,8 @@
#endif
#include "UICommon/UICommon.h"
#include "InputCommon/GCAdapter.h"
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/VideoBackendBase.h"
@ -226,6 +228,7 @@ int main(int argc, char* argv[])
UICommon::SetUserDirectory(user_directory);
UICommon::Init();
GCAdapter::Init();
s_platform = GetPlatform(options);
if (!s_platform || !s_platform->Init())

View File

@ -113,6 +113,7 @@
#include "DolphinQt/WiiUpdate.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/GCAdapter.h"
#include "UICommon/DiscordPresence.h"
#include "UICommon/GameFile.h"
@ -328,6 +329,7 @@ void MainWindow::InitControllers()
"No default device has been added in time. EmulatedController(s) defaulting adds"
" input mappings made for a specific default device depending on the platform");
}
GCAdapter::Init();
Pad::Initialize();
Pad::InitializeGBA();
Keyboard::Initialize();

View File

@ -75,7 +75,7 @@ static bool s_libusb_hotplug_enabled = false;
static libusb_hotplug_callback_handle s_hotplug_handle;
#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_out = 0;
@ -172,7 +172,7 @@ static void ScanThreadFunc()
if (s_libusb_hotplug_enabled)
{
if (libusb_hotplug_register_callback(
s_libusb_context,
*s_libusb_context,
(libusb_hotplug_event)(LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED |
LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT),
LIBUSB_HOTPLUG_ENUMERATE, 0x057e, 0x0337, LIBUSB_HOTPLUG_MATCH_ANY, HotplugCallback,
@ -218,6 +218,8 @@ void Init()
if (s_handle != nullptr)
return;
s_libusb_context = std::make_unique<LibusbUtils::Context>();
if (Core::GetState() != Core::State::Uninitialized && Core::GetState() != Core::State::Starting)
{
if ((CoreTiming::GetTicks() - s_last_init) < SystemTimers::GetTicksPerSecond())
@ -240,7 +242,7 @@ void StartScanThread()
{
if (s_adapter_detect_thread_running.IsSet())
return;
if (!s_libusb_context.IsValid())
if (!s_libusb_context->IsValid())
return;
s_adapter_detect_thread_running.Set(true);
s_adapter_detect_thread = std::thread(ScanThreadFunc);
@ -266,7 +268,7 @@ static void Setup()
s_controller_type.fill(ControllerTypes::CONTROLLER_NONE);
s_controller_rumble.fill(0);
s_libusb_context.GetDeviceList([](libusb_device* device) {
s_libusb_context->GetDeviceList([](libusb_device* device) {
if (CheckDeviceAccess(device))
{
// Only connect to a single adapter in case the user has multiple connected
@ -397,9 +399,10 @@ void Shutdown()
{
StopScanThread();
#if defined(LIBUSB_API_VERSION) && LIBUSB_API_VERSION >= 0x01000102
if (s_libusb_context.IsValid() && s_libusb_hotplug_enabled)
libusb_hotplug_deregister_callback(s_libusb_context, s_hotplug_handle);
if (s_libusb_context->IsValid() && s_libusb_hotplug_enabled)
libusb_hotplug_deregister_callback(*s_libusb_context, s_hotplug_handle);
#endif
s_libusb_context.reset();
Reset();
s_status = NO_ADAPTER_DETECTED;

View File

@ -108,7 +108,6 @@ void Init()
SConfig::Init();
Discord::Init();
Common::Log::LogManager::Init();
GCAdapter::Init();
VideoBackendBase::ActivateBackend(Config::Get(Config::MAIN_GFX_BACKEND));
Common::SetEnableAlert(Config::Get(Config::MAIN_USE_PANIC_HANDLERS));