Skip to content

Commit 0ce5743

Browse files
committed
Initialization order fixes
The old initialization order coudl cause a race condition resulting in dual execution of device initialization if a device behaved as if it was just plugged in when the init part of DILL was running.
1 parent 64c6ee5 commit 0ce5743

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/dill.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ std::string guid_to_string(GUID guid)
9292

9393
std::wstring unicode_string(guid_string);
9494
CoTaskMemFree(guid_string);
95+
9596
return std::string(unicode_string.begin(), unicode_string.end());
9697
}
9798

@@ -907,7 +908,7 @@ void enumerate_devices()
907908
break;
908909
}
909910
}
910-
911+
911912
if(g_device_change_callback != nullptr)
912913
{
913914
g_device_change_callback(di, DeviceActionType::Disconnected);
@@ -919,8 +920,11 @@ void enumerate_devices()
919920

920921
BOOL init()
921922
{
922-
logger->info("Initializing DILL v1.3");
923923
g_initialization_done = false;
924+
logger->info("Initializing DILL v1.3");
925+
926+
// Force an update of device enumeration to bootstrap everything
927+
enumerate_devices();
924928

925929
// Start joystick update loop thread
926930
g_joystick_thread = CreateThread(
@@ -955,10 +959,7 @@ BOOL init()
955959
return FALSE;
956960
}
957961

958-
// Force an update of device enumeration to bootstrap everything
959-
enumerate_devices();
960962
g_initialization_done = true;
961-
962963
return TRUE;
963964
}
964965

0 commit comments

Comments
 (0)