From 5b930c8486aa5a556fb48d892d62d7cc5cd64ee7 Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Mon, 6 Feb 2023 17:51:39 +0000 Subject: [PATCH] Fix feature gating in texture_binding_array example (#7425) # Objective Fixes #7374 ## Solution Move the feature gate into `main`, before `MaterialPlugin::` is added, as described in https://github.com/bevyengine/bevy/issues/7374#issuecomment-1405890519 --- examples/shader/texture_binding_array.rs | 36 +++++++++++++----------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/examples/shader/texture_binding_array.rs b/examples/shader/texture_binding_array.rs index 4c57bc073a..94e96d7762 100644 --- a/examples/shader/texture_binding_array.rs +++ b/examples/shader/texture_binding_array.rs @@ -14,9 +14,25 @@ use bevy::{ use std::num::NonZeroU32; fn main() { - App::new() - .add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest())) - .add_plugin(MaterialPlugin::::default()) + let mut app = App::new(); + app.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest())); + + let render_device = app.world.resource::(); + + // check if the device support the required feature + if !render_device + .features() + .contains(WgpuFeatures::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING) + { + error!( + "Render device doesn't support feature \ + SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING, \ + which is required for texture binding arrays" + ); + return; + } + + app.add_plugin(MaterialPlugin::::default()) .add_startup_system(setup) .run(); } @@ -31,21 +47,7 @@ fn setup( mut meshes: ResMut>, mut materials: ResMut>, asset_server: Res, - render_device: Res, ) { - // check if the device support the required feature - if !render_device - .features() - .contains(WgpuFeatures::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING) - { - error!( - "Render device doesn't support feature \ - SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING, \ - which is required for texture binding arrays" - ); - return; - } - commands.spawn(Camera3dBundle { transform: Transform::from_xyz(2.0, 2.0, 2.0).looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y), ..Default::default()