@@ -94,17 +94,21 @@ static tcpp::IInputStream* getInputStreamInclude(
94
94
95
95
// Figure out what line in the current file this #include was
96
96
// That would be the current lexer line, minus the line where the current file was included
97
- uint32_t lineGoBackTo = lexerLineIndex - includeStack. back (). first -
97
+ uint32_t lineInCurrentFileWithInclude = lexerLineIndex -
98
98
// if this is 2 includes deep (include within include), subtract leading import lines
99
99
// from the previous include
100
100
(includeStack.size () > 1 ? leadingLinesImports : 0 );
101
+ auto lastItemInIncludeStack = includeStack.back ();
101
102
102
103
IShaderCompiler::disableAllDirectivesExceptIncludes (res_str);
103
104
res_str = IShaderCompiler::encloseWithinExtraInclGuards (std::move (res_str), maxInclCnt, name.string ().c_str ());
104
105
res_str = res_str + " \n " +
105
- IShaderCompiler::PREPROC_DIRECTIVE_DISABLER + " line " + std::to_string (lineGoBackTo ).c_str () + " \" " + includeStack. back () .second .c_str () + " \"\n " ;
106
+ IShaderCompiler::PREPROC_DIRECTIVE_DISABLER + " line " + std::to_string (lineInCurrentFileWithInclude - lastItemInIncludeStack. first - 1 ).c_str () + " \" " + lastItemInIncludeStack .second .c_str () + " \"\n " ;
106
107
107
- includeStack.push_back (std::pair<uint32_t , std::string>(lineGoBackTo, IShaderCompiler::escapeFilename (name.string ())));
108
+ // Offset the lines this include takes up for subsequent includes
109
+ includeStack.back ().first += std::count (res_str.begin (), res_str.end (), ' \n ' );
110
+
111
+ includeStack.push_back (std::pair<uint32_t , std::string>(lineInCurrentFileWithInclude, IShaderCompiler::escapeFilename (name.string ())));
108
112
109
113
return new tcpp::StringInputStream (std::move (res_str));
110
114
}
0 commit comments