From 34896d8e89022935cde02b07f2b22e5a2dff5b4f Mon Sep 17 00:00:00 2001 From: bitsawer Date: Wed, 26 Apr 2023 16:48:23 +0300 Subject: [PATCH] Fix Shader Preprocessor line numbering when disabled --- servers/rendering/shader_preprocessor.cpp | 16 ++++++---------- servers/rendering/shader_preprocessor.h | 4 ++-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/servers/rendering/shader_preprocessor.cpp b/servers/rendering/shader_preprocessor.cpp index ff1d55f9051..0644f5918cc 100644 --- a/servers/rendering/shader_preprocessor.cpp +++ b/servers/rendering/shader_preprocessor.cpp @@ -54,9 +54,9 @@ int ShaderPreprocessor::Tokenizer::get_index() const { return index; } -void ShaderPreprocessor::Tokenizer::get_and_clear_generated(Vector *r_out) { - for (int i = 0; i < generated.size(); i++) { - r_out->push_back(generated[i]); +void ShaderPreprocessor::Tokenizer::get_and_clear_generated(LocalVector *r_out) { + for (uint32_t i = 0; i < generated.size(); i++) { + r_out->push_back(generated[i].text); } generated.clear(); } @@ -1206,18 +1206,14 @@ Error ShaderPreprocessor::preprocess(State *p_state, const String &p_code, Strin break; } + // Add autogenerated tokens if there are any. + p_tokenizer.get_and_clear_generated(&output); + if (state->disabled) { // Preprocessor was disabled. // Read the rest of the file into the output. output.push_back(t.text); continue; - } else { - // Add autogenerated tokens. - Vector generated; - p_tokenizer.get_and_clear_generated(&generated); - for (int i = 0; i < generated.size(); i++) { - output.push_back(generated[i].text); - } } if (t.text == '#') { diff --git a/servers/rendering/shader_preprocessor.h b/servers/rendering/shader_preprocessor.h index f198af66f0e..406b6632282 100644 --- a/servers/rendering/shader_preprocessor.h +++ b/servers/rendering/shader_preprocessor.h @@ -83,7 +83,7 @@ private: int line; int index; int size; - Vector generated; + LocalVector generated; private: void add_generated(const Token &p_t); @@ -95,7 +95,7 @@ private: char32_t peek(); int consume_line_continuations(int p_offset); - void get_and_clear_generated(Vector *r_out); + void get_and_clear_generated(LocalVector *r_out); void backtrack(char32_t p_what); LocalVector advance(char32_t p_what); void skip_whitespace();