Skip to content

Commit a449f38

Browse files
julienamsellemEvergreen
authored andcommitted
[VFX] Fixed parsing "int" parameter without access modifier
Steps to reproduce: 1. Create a new VFX Graph 2. Add a Custom HLSL block 3. Open the HLSL code editor by clicking on the edit button 4. Copy / paste the function below: ```hlsl void CustomHLSL(inout VFXAttributes attributes, int e) { //Nothing } ``` Actual results: The VFX does not compile (the int type is misinterpreted as in access modifier) Expected results: The VFX compiles fine Reproducible with versions: 6000.01f1
1 parent 4c6d5c5 commit a449f38

File tree

2 files changed

+24
-2
lines changed
  • Packages/com.unity.visualeffectgraph/Editor/Models/Blocks/Implementations/HLSL
  • Tests/SRPTests/Projects/VisualEffectGraph_HDRP/Assets/AllTests/Editor/Tests

2 files changed

+24
-2
lines changed

Packages/com.unity.visualeffectgraph/Editor/Models/Blocks/Implementations/HLSL/HLSLParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class HLSLVFXAttributeAccessError : IHLSMessage
4646
public string message => "Missing `inout` access modifier before the VFXAttributes type.\nNeeded because your code writes to at least one attribute.";
4747
public VFXErrorType type => VFXErrorType.Error;
4848
}
49-
49+
5050
class HLSLMissingVFXAttribute : IHLSMessage
5151
{
5252
public string message => "Missing `VFXAttributes attributes` as function's parameter";
@@ -165,7 +165,7 @@ public HLSLMissingIncludeFile(string filePath)
165165
class HLSLFunctionParameter
166166
{
167167
// Match inout/in/out accessor then any whitespace then the parameter type then optionally a template type any whitespace and then the parameter name
168-
static readonly Regex s_ParametersParser = new Regex(@"(?<access>inout|in|out)?\s*(?<type>\w+)(?:[<](?<template>\w+)[>])?\s*(?<parameter>\w+)(?:,\s*)?", RegexOptions.Compiled);
168+
static readonly Regex s_ParametersParser = new Regex(@"(?<access>(inout|in|out)\b)?\s*(?<type>\w+)(?:[<](?<template>\w+)[>])?\s*(?<parameter>\w+)(?:,\s*)?", RegexOptions.Compiled);
169169

170170
readonly string m_RawCode;
171171

Tests/SRPTests/Projects/VisualEffectGraph_HDRP/Assets/AllTests/Editor/Tests/HLSLParserTest.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,28 @@ public void HLSL_Check_Nested_Curly_Bracket()
354354
// Assert
355355
CollectionAssert.IsNotEmpty(functions);
356356
}
357+
358+
[Test, Description("Covers issue UUM-71490")]
359+
public void HLSL_Check_Int_Without_Access_Modifier()
360+
{
361+
// Arrange
362+
var hlslCode =
363+
$"void Repro(inout VFXAttributes attributes, int parameter)" +
364+
"{\n" +
365+
" // Nothing\n" +
366+
"}\n";
367+
368+
// Act
369+
var functions = HLSLFunction.Parse(this.attributesManager, hlslCode).ToArray();
370+
371+
// Assert
372+
CollectionAssert.IsNotEmpty(functions);
373+
var parameters = functions[0].inputs.ToArray();
374+
Assert.AreEqual(2, parameters.Length);
375+
Assert.AreEqual("int", parameters[1].rawType);
376+
Assert.AreEqual(typeof(int), parameters[1].type);
377+
Assert.AreEqual(HLSLAccess.NONE, parameters[1].access);
378+
}
357379
}
358380
}
359381
#endif

0 commit comments

Comments
 (0)