Simple DrawMeshInstanced crashes unity 2018.3

Good evening, I am facing an issue with Unity 2018.3f2, where a simple draw mesh instance causes the editor to crash, constantly with the following stack trace:

Stack Trace of Crashed Thread 21800:
0x0000000140B969C0 (Unity) FindDataSource
0x0000000140B7C74E (Unity) WriteConstantLoop<MemCpy<CopyFloat,4> >
0x0000000140B7961F (Unity) InstancingProps::FillInstanceBufferDispatchConstants<Instancing::smile:rawAPIArgs>
0x0000000140B6F213 (Unity) InstanceBufferJob<Instancing::smile:rawAPIArgs>
0x00000001408A4D38 (Unity) JobQueue::Exec
0x00000001408A6C7D (Unity) JobQueue::Steal
0x00000001408A4FC2 (Unity) JobQueue::ExecuteJobFromQueue
0x00000001408A53C2 (Unity) JobQueue::ProcessJobs
0x00000001408A7403 (Unity) JobQueue::WorkLoop
0x0000000140A6F094 (Unity) Thread::RunThreadWrapper
0x00007FFE310B7E94 (KERNEL32) BaseThreadInitThunk
0x00007FFE33C3A251 (ntdll) RtlUserThreadStart

The component needed to crash is super simple:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;

public class shouldCrash : MonoBehaviour
{
    public GameObject mesh;
    public Material mat;
    private Mesh m;
    private Matrix4x4[] matrices;
    private CommandBuffer cmd;
    // Start is called before the first frame update

    private void ensureCommandBuffer() {
        if (cmd == null) {
          cmd = new CommandBuffer();
        }
      }
    void Start()
    {
        var mf = mesh.GetComponent<MeshFilter>();
        m= mf.sharedMesh;
        matrices = new Matrix4x4[200];
        for(int i =0; i <200;++i)
        {
            matrices[i] = Matrix4x4.identity;

        }
        ensureCommandBuffer();
        var camera = Camera.main;
        camera.AddCommandBuffer(CameraEvent.AfterGBuffer, cmd);
    }

    // Update is called once per frame
    void Update()
    {
        ensureCommandBuffer();
        cmd.Clear();

        int deferredPassIndex = mat.FindPass("DEFERRED");
        //int deferredPassIndex = m_material.FindPass("FORWARD");
        cmd.EnableShaderKeyword("LIGHTPROBE_SH");
        cmd.EnableShaderKeyword("UNITY_HDR_ON ");
        for(int i=0; i <4;++i)
        {
            cmd.DrawMeshInstanced(m,0,mat,deferredPassIndex,matrices,178);
        }

       
    }
}

I am attaching the full project and crash log. Does anyone have any idea about this?
https://drive.google.com/file/d/1W96IRmbgaVmWM0mBANx_W1vlp7BHi6wt/view?usp=sharing
best regards

M.

It absolutely should not crash. Please report a bug with this and it will get tracked and fixed.

@joelv will do, are you aware of any workaround? I found similar bug that was supposedly be fixed in 2019 and back-ported 2018, (this still crashes in 2019). It had to do with material property block , but other than defining some matrices per instance in the shaders I could not find anything related to properties, like color etc. So doesn’t seem to be crashing because the property block is not provided.

Sadly I don’t. But I will poke the people who maintain this and we can see if they can come up with something

Done:
https://fogbugz.unity3d.com/default.asp?1115627_5acisjfuehm6mi0q
Thank you for all the help.

M.

I’m using 2018.2.20f1, facing the same problem, and because of plugins we used that can’t upgrade to 2019.2.

This post [Unity 2018.3.0b3] Crash by instancing rendering code ?tdsourcetag=s_pcqq_aiomsg said some properties should be provided, but I don’t know what instance property I have missed.

Dear devs, since this crash was fixed for Unity 2019.1+, is there any plans to backport it for 2018.4 LTS?

I’m not sure why this wasn’t backported to 2018.4, sorry about that! I’ve raised a ticket internally for it to be backported.

1 Like

Thank you for the quick response, Richard. Glad to hear that!

1 Like