Skip to content

Commit 6a60070

Browse files
committed
Normalize Wave EOF handling
Normalize root and include source buffers before lexing so EOF comments without a trailing newline no longer trip Wave. Thanks-to: @Themperror for the repros
1 parent f727158 commit 6a60070

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

src/nbl/asset/utils/CHLSLCompiler.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,12 @@ static void normalizeLegacyShaderStagePragmas(std::string& code)
440440
code = std::move(normalized);
441441
}
442442

443+
static void ensureTrailingNewline(std::string& code)
444+
{
445+
if (!code.empty() && code.back() != '\n' && code.back() != '\r')
446+
code.push_back('\n');
447+
}
448+
443449
static std::string preprocessShaderImpl(
444450
std::string&& code,
445451
IShader::E_SHADER_STAGE& stage,
@@ -464,6 +470,7 @@ static std::string preprocessShaderImpl(
464470
dependenciesOut = &localDependencies;
465471

466472
normalizeLegacyShaderStagePragmas(code);
473+
ensureTrailingNewline(code);
467474

468475
// preprocess
469476
core::string resolvedString = nbl::wave::preprocess(code, preprocessOptions, bool(dependenciesOut),

src/nbl/asset/utils/waveContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ struct load_to_string final
2929
static void init_iterators(IterContextT& iter_ctx, PositionT const& act_pos, boost::wave::language_support language)
3030
{
3131
iter_ctx.instring = iter_ctx.ctx.get_located_include_content();
32+
if (!iter_ctx.instring.empty() && iter_ctx.instring.back() != '\n' && iter_ctx.instring.back() != '\r')
33+
iter_ctx.instring.push_back('\n');
3234

3335
using iterator_type = IterContextT::iterator_type;
3436
iter_ctx.first = iterator_type(iter_ctx.instring.begin(),iter_ctx.instring.end(),PositionT(iter_ctx.filename),language);

0 commit comments

Comments
 (0)