瀏覽代碼

Do not probe joypads if DirectInput cannot be initialized.

Marcel Admiraal 5 年之前
父節點
當前提交
97a529b1d8
共有 1 個文件被更改,包括 9 次插入6 次删除
  1. 9 6
      platform/windows/joypad_windows.cpp

+ 9 - 6
platform/windows/joypad_windows.cpp

@@ -67,13 +67,16 @@ JoypadWindows::JoypadWindows(HWND *hwnd) {
 	for (int i = 0; i < JOYPADS_MAX; i++)
 		attached_joypads[i] = false;
 
-	HRESULT result;
-	result = DirectInput8Create(GetModuleHandle(nullptr), DIRECTINPUT_VERSION, IID_IDirectInput8, (void **)&dinput, nullptr);
-	if (FAILED(result)) {
-		printf("Couldn't initialize DirectInput: %ld\n", result);
-		printf("Rebooting your PC may solve this issue.\n");
+	HRESULT result = DirectInput8Create(GetModuleHandle(nullptr), DIRECTINPUT_VERSION, IID_IDirectInput8, (void **)&dinput, nullptr);
+	if (result == DI_OK) {
+		probe_joypads();
+	} else {
+		ERR_PRINT("Couldn't initialize DirectInput. Error: " + itos(result));
+		if (result == DIERR_OUTOFMEMORY) {
+			ERR_PRINT("The Windows DirectInput subsystem could not allocate sufficient memory.");
+			ERR_PRINT("Rebooting your PC may solve this issue.");
+		}
 	}
-	probe_joypads();
 }
 
 JoypadWindows::~JoypadWindows() {