Skip to content

Commit

Permalink
support all line endings in shader preprocessor (#3603)
Browse files Browse the repository at this point in the history
# Objective

- Advance uses of shaders seems to often fail for Windows users
- Bevy split lines on `'\n'` which messes with windows line endings

## Solution

- Uses Rust built in https://doc.rust-lang.org/std/primitive.str.html#method.lines
  • Loading branch information
mockersf committed Jan 9, 2022
1 parent e566853 commit 600ee7e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions crates/bevy_render/src/render_resource/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl ShaderImportProcessor {

pub fn get_imports_from_str(&self, shader: &str) -> Vec<ShaderImport> {
let mut imports = Vec::new();
for line in shader.split('\n') {
for line in shader.lines() {
if let Some(cap) = self.import_asset_path_regex.captures(line) {
let import = cap.get(1).unwrap();
imports.push(ShaderImport::AssetPath(import.as_str().to_string()));
Expand Down Expand Up @@ -366,7 +366,7 @@ impl ShaderProcessor {
let shader_defs_unique = HashSet::<String>::from_iter(shader_defs.iter().cloned());
let mut scopes = vec![true];
let mut final_string = String::new();
for line in shader_str.split('\n') {
for line in shader_str.lines() {
if let Some(cap) = self.ifdef_regex.captures(line) {
let def = cap.get(1).unwrap();
scopes.push(*scopes.last().unwrap() && shader_defs_unique.contains(def.as_str()));
Expand Down Expand Up @@ -417,7 +417,6 @@ impl ShaderProcessor {
final_string.push('\n');
}
}
final_string.pop();

if scopes.len() != 1 {
return Err(ProcessShaderError::NotEnoughEndIfs);
Expand Down

0 comments on commit 600ee7e

Please sign in to comment.