diff --git a/servers/rendering/shader_compiler.cpp b/servers/rendering/shader_compiler.cpp index c23ba8ee010..6f49a8fe4ec 100644 --- a/servers/rendering/shader_compiler.cpp +++ b/servers/rendering/shader_compiler.cpp @@ -1520,6 +1520,17 @@ Error ShaderCompiler::compile(RS::ShaderMode p_mode, const String &p_code, Ident // Print the files. for (const KeyValue> &E : includes) { + int err_line = -1; + for (const ShaderLanguage::FilePosition &include_position : include_positions) { + if (include_position.file == E.key) { + err_line = include_position.line; + } + } + if (err_line < 0) { + // Skip files that don't contain errors. + continue; + } + if (E.key.is_empty()) { if (p_path == "") { print_line("--Main Shader--"); @@ -1529,19 +1540,14 @@ Error ShaderCompiler::compile(RS::ShaderMode p_mode, const String &p_code, Ident } else { print_line("--" + E.key + "--"); } - int err_line = -1; - for (int i = 0; i < include_positions.size(); i++) { - if (include_positions[i].file == E.key) { - err_line = include_positions[i].line; - } - } const Vector &V = E.value; for (int i = 0; i < V.size(); i++) { if (i == err_line - 1) { // Mark the error line to be visible without having to look at // the trace at the end. print_line(vformat("E%4d-> %s", i + 1, V[i])); - } else { + } else if ((i == err_line - 3) || (i == err_line - 2) || (i == err_line) || (i == err_line + 1)) { + // Print 4 lines around the error line. print_line(vformat("%5d | %s", i + 1, V[i])); } }