Skip to content

Commit

Permalink
Fix error when creating WARP device on Windows (#300)
Browse files Browse the repository at this point in the history
* Removed unused device context that was leaked

* Use null adapter when creating a WARP device

* Fixed formatting
  • Loading branch information
crbrz authored Jul 26, 2024
1 parent c9c0c2b commit e077b41
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/platform/windows/angle/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ use winapi::shared::dxgi::{self, IDXGIAdapter, IDXGIDevice, IDXGIFactory1};
use winapi::shared::minwindef::UINT;
use winapi::shared::winerror::{self, S_OK};
use winapi::um::d3d11::{D3D11CreateDevice, ID3D11Device, D3D11_SDK_VERSION};
use winapi::um::d3dcommon::{D3D_DRIVER_TYPE, D3D_DRIVER_TYPE_UNKNOWN, D3D_FEATURE_LEVEL_9_3};
use winapi::um::d3dcommon::{
D3D_DRIVER_TYPE, D3D_DRIVER_TYPE_UNKNOWN, D3D_DRIVER_TYPE_WARP, D3D_FEATURE_LEVEL_9_3,
};
use winapi::Interface;
use wio::com::ComPtr;

Expand Down Expand Up @@ -167,9 +169,13 @@ impl Device {
unsafe {
let mut d3d11_device = ptr::null_mut();
let mut d3d11_feature_level = 0;
let mut d3d11_device_context = ptr::null_mut();
let d3d11_adapter = if d3d_driver_type == D3D_DRIVER_TYPE_WARP {
ptr::null_mut()
} else {
adapter.dxgi_adapter.as_raw()
};
let result = D3D11CreateDevice(
adapter.dxgi_adapter.as_raw(),
d3d11_adapter,
d3d_driver_type,
ptr::null_mut(),
0,
Expand All @@ -178,7 +184,7 @@ impl Device {
D3D11_SDK_VERSION,
&mut d3d11_device,
&mut d3d11_feature_level,
&mut d3d11_device_context,
ptr::null_mut(),
);
if !winerror::SUCCEEDED(result) {
return Err(Error::DeviceOpenFailed);
Expand Down

0 comments on commit e077b41

Please sign in to comment.