Merge pull request 'Add bounds checking for D3D9 adapter number' (#29) from Bottersnike/segatools:fix/adapter_range into develop

Reviewed-on: Dniel97/segatools#29
This commit is contained in:
Dniel97 2024-08-19 13:54:58 +00:00
commit 6a4cae1165

View File

@ -224,9 +224,19 @@ static HRESULT STDMETHODCALLTYPE my_IDirect3D9_CreateDevice(
gfx_util_frame_window(hwnd); gfx_util_frame_window(hwnd);
} }
dprintf("Gfx: Using adapter %d\n", gfx_config.monitor); UINT max_adapter = IDirect3D9_GetAdapterCount(real);
adapter = gfx_config.monitor;
if (adapter >= max_adapter) {
dprintf(
"Gfx: Requested adapter %d but maximum is %d. Using primary monitor\n",
gfx_config.monitor, max_adapter - 1
);
adapter = D3DADAPTER_DEFAULT;
} else {
dprintf("Gfx: Using adapter %d\n", gfx_config.monitor);
}
return IDirect3D9_CreateDevice(real, gfx_config.monitor, type, hwnd, flags, pp, pdev); return IDirect3D9_CreateDevice(real, adapter, type, hwnd, flags, pp, pdev);
} }
static HRESULT STDMETHODCALLTYPE my_IDirect3D9Ex_CreateDevice( static HRESULT STDMETHODCALLTYPE my_IDirect3D9Ex_CreateDevice(