From 485dab9a527d3bbd429dd0743156eb858d85b0b1 Mon Sep 17 00:00:00 2001 From: Kunal Mohan Date: Wed, 23 Sep 2020 00:30:50 +0530 Subject: [PATCH] Prevent an invalid texture from being registered in device_create_texture --- wgpu-core/src/device/mod.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 9bef06da55..d52ab168b2 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -1262,6 +1262,16 @@ impl Global { let device = device_guard .get(device_id) .map_err(|_| DeviceError::Invalid)?; + + let texture_features = conv::texture_features(desc.format); + if texture_features != wgt::Features::empty() && !device.features.contains(texture_features) + { + return Err(resource::CreateTextureError::MissingFeature( + texture_features, + desc.format, + )); + } + let texture = device.create_texture(device_id, desc)?; let num_levels = texture.full_range.levels.end; let num_layers = texture.full_range.layers.end; @@ -1276,15 +1286,6 @@ impl Global { None => (), }; - let texture_features = conv::texture_features(desc.format); - if texture_features != wgt::Features::empty() && !device.features.contains(texture_features) - { - return Err(resource::CreateTextureError::MissingFeature( - texture_features, - desc.format, - )); - } - device .trackers .lock()