@@ -94,17 +94,21 @@ static tcpp::IInputStream* getInputStreamInclude(
9494
9595 // Figure out what line in the current file this #include was
9696 // 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 -
9898 // if this is 2 includes deep (include within include), subtract leading import lines
9999 // from the previous include
100100 (includeStack.size () > 1 ? leadingLinesImports : 0 );
101+ auto lastItemInIncludeStack = includeStack.back ();
101102
102103 IShaderCompiler::disableAllDirectivesExceptIncludes (res_str);
103104 res_str = IShaderCompiler::encloseWithinExtraInclGuards (std::move (res_str), maxInclCnt, name.string ().c_str ());
104105 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 " ;
106107
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 ())));
108112
109113 return new tcpp::StringInputStream (std::move (res_str));
110114}
0 commit comments