microsoft / MixedRealityToolkit-Unity

This repository is for the legacy Mixed Reality Toolkit (MRTK) v2. For the latest version of the MRTK please visit https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity
https://aka.ms/mrtkdocs
MIT License
6k stars 2.12k forks source link

Exception "Instancing is not supported" on platform that doesn't support GPU draw call instancing #8600

Closed Rufus31415 closed 4 years ago

Rufus31415 commented 4 years ago

Describe the bug

If you enable the visual profiler, an InvalidOperationException: "Instancing is not supported" could occur in MixedRealityToolkitVisualProfiler.cs line 384, if the platform doesn't support GPU draw call instancing. The method Graphics.DrawMeshInstanced() throws this exception.

To reproduce

WebGL 1.0 doesn't support it for example.

  1. Change your Unity platform to WebGL
  2. Edit -> Graphics emulation -> "WebGL 1.0"
  3. Play in editor and you will get the exception at each frame

You can also compile for WebGL and execute it in a browser that only support WebGL 1.0.

Expected behavior

A clear and concise description of what you expected to happen.

Setup

Target platform

Additional context

In MixedRealityToolkitVisualProfiler.cs, you already bypass Graphics.DrawMeshInstanced() if defaultInstancedMaterial == null, you coud just add the condition SystemInfo.supportsInstancing :

if (defaultInstancedMaterial != null && SystemInfo.supportsInstancing)
{
  frameInfoPropertyBlock.SetMatrix(parentMatrixID, parentLocalToWorldMatrix);
  Graphics.DrawMeshInstanced(quadMesh, 0, defaultInstancedMaterial, frameInfoMatrices, frameInfoMatrices.Length, frameInfoPropertyBlock, UnityEngine.Rendering.ShadowCastingMode.Off, false);
}
else
{
...
}
keveleigh commented 4 years ago

Thanks for reporting this and proposing a fix!

Fixed in 2.5 via https://github.com/microsoft/MixedRealityToolkit-Unity/pull/8613