From 4a5bcccde2d125acf666dd257b851ec8f78f7c70 Mon Sep 17 00:00:00 2001 From: James R <71466513+ColdIce1605@users.noreply.github.com> Date: Wed, 9 Dec 2020 18:34:22 -0600 Subject: [PATCH] Don't panic when attempting to set shader defs from an asset that hasn't loaded yet (#1035) Don't panic when attempting to set shader defs from an asset that hasn't loaded yet --- crates/bevy_render/src/shader/shader_defs.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/bevy_render/src/shader/shader_defs.rs b/crates/bevy_render/src/shader/shader_defs.rs index b8ff477745acd..977872462732c 100644 --- a/crates/bevy_render/src/shader/shader_defs.rs +++ b/crates/bevy_render/src/shader/shader_defs.rs @@ -98,14 +98,16 @@ pub fn asset_shader_defs_system( T: ShaderDefs + Send + Sync + 'static, { for (asset_handle, mut render_pipelines) in query.iter_mut() { - let shader_defs = assets.get(asset_handle).unwrap(); - for shader_def in shader_defs.iter_shader_defs() { - for render_pipeline in render_pipelines.pipelines.iter_mut() { - render_pipeline - .specialization - .shader_specialization - .shader_defs - .insert(shader_def.to_string()); + if let Some(asset_handle) = assets.get(asset_handle) { + let shader_defs = asset_handle; + for shader_def in shader_defs.iter_shader_defs() { + for render_pipeline in render_pipelines.pipelines.iter_mut() { + render_pipeline + .specialization + .shader_specialization + .shader_defs + .insert(shader_def.to_string()); + } } } }