diff --git a/src/Nazara/Shader/Ast/SanitizeVisitor.cpp b/src/Nazara/Shader/Ast/SanitizeVisitor.cpp index 6500f85d1..f197274dc 100644 --- a/src/Nazara/Shader/Ast/SanitizeVisitor.cpp +++ b/src/Nazara/Shader/Ast/SanitizeVisitor.cpp @@ -1427,8 +1427,6 @@ namespace Nz::ShaderAst return CloneFor(); //< can't resolve step value } - PushScope(); - auto multi = std::make_unique(); auto Unroll = [&](auto dummy) @@ -1441,6 +1439,10 @@ namespace Nz::ShaderAst for (; counter < to; counter += step) { + PushScope(); + + auto innerMulti = std::make_unique(); + auto constant = ShaderBuilder::Constant(counter); constant->sourceLocation = node.sourceLocation; @@ -1448,9 +1450,13 @@ namespace Nz::ShaderAst var->sourceLocation = node.sourceLocation; Validate(*var); - multi->statements.emplace_back(std::move(var)); + innerMulti->statements.emplace_back(std::move(var)); - multi->statements.emplace_back(Unscope(CloneStatement(node.statement))); + innerMulti->statements.emplace_back(Unscope(CloneStatement(node.statement))); + + multi->statements.emplace_back(ShaderBuilder::Scoped(std::move(innerMulti))); + + PopScope(); } }; @@ -1468,8 +1474,6 @@ namespace Nz::ShaderAst throw ShaderLang::AstInternalError{ node.sourceLocation, "unexpected counter type " }; } - PopScope(); - return multi; } }