Skip to content

Slang Language Server crashing on private __init #7823

@tdavidovicNV

Description

@tdavidovicNV

This is a very hard to reproduce crash, but once it gets going, it cannot recover.

I have a piece of code that looks like this:

bsdf.slang:

module bsdfs;
__include lambert_diffuse_btdf;

public struct BSDFContext
{
    float iorI;  ///< IOR from incidence medium
    float iorT;  ///< IOR trom transmission medium
    bool inited; ///< Flag to indicate if the struct was initialized

    __init(float iorI_, float iorT_)
    {
        iorI = iorI_;
        iorT = iorT_;
        inited = true;
    }

    __init()
    {
        iorI = 1.f;
        iorT = 1.f;
        inited = false;
    }
}

public interface IBSDF
{
    public float3 eval<S : ISampleGenerator>(const float3 wi, const float3 wo, inout S sg, BSDFContext bc);
}

(ISampleGenerator is an interface from another module, probably not relevant)

lambert_diffuse_btdf.slang

implementing bsdfs;
public struct LambertDiffuseBTDF : IBSDF, IDifferentiable
{
    float3 albedo = {}; ///< Diffuse albedo.
    __init(float3 albedo_)
    {
        this.albedo = albedo_;
    }

    [Differentiable]
    public float3 eval<S : ISampleGenerator>(const float3 wi, const float3 wo, inout S sg, BSDFContext bc)
    {
        if (min(wi.z, -wo.z) < kMinCosTheta)
            return float3(0.f);

        return float.INV_PI * albedo * -wo.z;
    }
}

(note the __init lacking public keyword).

When I then try to use the LambertDiffuseBTDF from another module like this:

make_bsdfs.slang

__exported import materials.bsdfs.bsdfs;

LambertDiffuseBTDF createTranslucent(float3 color, float3 normal)
{
    return LambertDiffuseBTDF( color );
}

The Slang Language Server crashes. Taking down vscode and restarting it doesn't help (it crashes right away). Commenting, taking down vscode, restarting and uncommenting the createTranslucent also crashes it right away.

Adding public to the __init in LambertDiffuseBTDF fixes the issue (and actually makes for a valid code).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions