Skip to content

NullReferenceException when compiling shaders containing buffer pointers with reflection #39

@nicolasgustafsson

Description

@nicolasgustafsson

The reflection throws NullReferenceException trying to parse pointers in the json. Compiling without reflection data works as expected.

Version: Slangc.NET 2025.19.1

Stacktrace:

   at Slangc.NET.SlangType.PointerProperties..ctor(JsonObject reader)
   at Slangc.NET.SlangType..ctor(JsonObject reader)
   at Slangc.NET.SlangVar..ctor(JsonObject reader)
   at Slangc.NET.SlangType.StructProperties.<>c.<.ctor>b__0_0(JsonNode reader)
   at System.Linq.Enumerable.IListSelectIterator`2.Fill(IList`1 source, Span`1 results, Func`2 func)
   at System.Linq.Enumerable.IListSelectIterator`2.ToArray()
   at Slangc.NET.SlangType.StructProperties..ctor(JsonObject reader)
   at Slangc.NET.SlangType..ctor(JsonObject reader)
   at Slangc.NET.SlangParameter..ctor(JsonObject reader)
   at Slangc.NET.SlangReflection.<>c.<.ctor>b__2_0(JsonNode reader)
   at System.Linq.Enumerable.IListSelectIterator`2.Fill(IList`1 source, Span`1 results, Func`2 func)
   at System.Linq.Enumerable.IListSelectIterator`2.ToArray()
   at Slangc.NET.SlangReflection..ctor(IntPtr request, Boolean parseJson)
   at Slangc.NET.SlangCompiler.CompileWithReflection(String[] args, SlangReflection& reflection)

Repro shader code:

struct Vertex 
{
    float3 position;
};

struct VertexStageOutput
{
    float4          sv_position     : SV_Position;
};

struct VertexBuffer
{
    Vertex vertices[];
}

struct InputData 
{
    VertexBuffer* VertexBuffer;
};

InputData PushConstants; 

[shader("vertex")]
VertexStageOutput main(uint vertexID : SV_VertexID)
{
    VertexStageOutput output;
    
    return output; 
}

Repro:

  1. Compile above shader code with reflection.

Expected Result:
Shader successfully compiles, and the reflection out parameter is set.

Actual Result:
CompileWithReflection throws NullReferenceException.

Workaround:
Copying the entire SlangCompiler class, and changing SlangReflection constructor argument to not parse the json should allow me to manually parse the json myself, though I have not tried this yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions