Skip to content

Commit 9ad546e

Browse files
authored
fix module name for AssetPath shaders (#9186)
# Objective AssetPath shader imports check if the shader is added using the path without quotes. this causes them to be re-added even if already present, which can cause previous dependents to get unloaded leading to a "missing import" error. ## Solution fix the module name of AssetPath shaders used for checking if it's already added to correctly use the quoted name.
1 parent a30da00 commit 9ad546e

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

crates/bevy_render/src/render_resource/pipeline_cache.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl ShaderCache {
214214
shaders: &HashMap<Handle<Shader>, Shader>,
215215
import: &ShaderImport,
216216
) -> Result<(), PipelineCacheError> {
217-
if !composer.contains_module(import.as_str()) {
217+
if !composer.contains_module(&import.module_name()) {
218218
if let Some(shader_handle) = import_path_shaders.get(import) {
219219
if let Some(shader) = shaders.get(shader_handle) {
220220
for import in &shader.imports {
@@ -366,7 +366,8 @@ impl ShaderCache {
366366
shaders_to_clear.extend(data.dependents.iter().map(|h| h.clone_weak()));
367367

368368
if let Some(Shader { import_path, .. }) = self.shaders.get(&handle) {
369-
self.composer.remove_composable_module(import_path.as_str());
369+
self.composer
370+
.remove_composable_module(&import_path.module_name());
370371
}
371372
}
372373
}

crates/bevy_render/src/render_resource/shader.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,10 @@ pub enum ShaderImport {
303303
}
304304

305305
impl ShaderImport {
306-
pub fn as_str(&self) -> &str {
306+
pub fn module_name(&self) -> Cow<'_, String> {
307307
match self {
308-
ShaderImport::AssetPath(s) | ShaderImport::Custom(s) => s,
308+
ShaderImport::AssetPath(s) => Cow::Owned(format!("\"{s}\"")),
309+
ShaderImport::Custom(s) => Cow::Borrowed(s),
309310
}
310311
}
311312
}

0 commit comments

Comments
 (0)