Graphics.RenderPrimitives not working in build

I have a script that’s drawing grass quads by sending a material a ComputeBuffer of vertices and calling Graphics.RenderPrimitives. It works fine in the editor but doesn’t show up when I run a build. If I connect the frame debugger to the build I can see that the GPU isn’t receiving any draw calls for the grass, and in the player log I get these three errors every frame:

Can't allocate buffers from graphics jobs
Can't initialize buffers from graphics jobs
Unable to create ProceduralQuad Index Buffer

This is the code for drawing the quads:

    void SetupMaterial()
    {
        ReleaseBuffers();

        if (sharedMaterial == null)
        {
            return;
        }

        material = new Material(sharedMaterial)
        {
            hideFlags = HideFlags.DontSave
        };

        Matrix4x4 matrix = transform.localToWorldMatrix;
        Vector3 center = matrix.MultiplyPoint3x4(Vector3.zero);
        bounds.center = center;
        Vector3 bottomLeft = matrix.MultiplyPoint3x4(size * -0.5f);
        Vector3 topRight = matrix.MultiplyPoint3x4(size * 0.5f);
        bounds.SetMinMax(Vector3.Min(bottomLeft, topRight), Vector3.Max(bottomLeft, topRight));

        vertexBuffer = new ComputeBuffer(vertices.Length, sizeof(float), ComputeBufferType.Structured, ComputeBufferMode.Immutable);
        vertexBuffer.SetData(vertices);
        material.SetBuffer("_Vertices", vertexBuffer);
        material.SetInteger("_NumVertices", vertices.Length);
        material.SetVector("_GridSize", new Vector4(numPointsX, numPointsZ));
        material.SetVector("_VolumeBounds", new Vector4(center.x, center.z, size.x, size.z));
        material.SetVector("_GridPosition", new Vector4(bottomLeft.x, bottomLeft.z, 1f / pointsPerMeter));

        renderParams.material = material;
        renderParams.worldBounds = bounds;
        renderParams.renderingLayerMask = 1u;
    }

    public void ReleaseBuffers()
    {
        if (vertexBuffer != null)
        {
            vertexBuffer.Release();
            vertexBuffer = null;
        }

        if (material)
        {
            CoreUtils.Destroy(material);
            material = null;
        }
    }

    void Start()
    {
        SetupMaterial();
    }

    void OnDisable()
    {
        ReleaseBuffers();
    }

    void Update()
    {
        Draw();
    }

    void Draw()
    {
        Graphics.RenderPrimitives(renderParams, meshTopology, 4, (int)(vertices.Length * density));
    }

Does anyone know what might be causing this? I’m in 2022.3.5 using URP.

Thanks!

I don’t know if this will be helpful, but I usually put any SetBuffer() calls (or the whole property setup really) into the Draw() method right before you call Graphics.RenderPrimitives(). In my case this fixed issues before, where things weren’t being rendered after the application lost/regained focus.

I also want to add that in the documentation example for Graphics.RenderPrimitives they call SetBuffer on the renderParams instead of the material, although I’m not sure it makes a difference.

Did this get fixed? You could try after disabling graphics jobs in project settings

I had the same issue, tried with disabling this setting, did not fix it