-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Describe the bug
ClippingPrimitive has functionality to automatically remove renderers that have been destroyed (renderer == null), but when doing so, it will have an unhandled MissingReferenceException in 2.8.0.
To reproduce
Steps to reproduce the behavior:
- Add a ClippingPrimitive (ClippingSphere, ClippingBox or ClippingPlane) to a GameObject in your scene.
- Add the Renderer of another GameObject to the 'Renderers' list on your ClippingPrimitive.
- Enter play mode
- Delete the GameObject with the Renderer assigned to your ClippingPrimitive
- Move ClippingPrimitive Transform a bit (will set IsDirty = true)
Expected behavior
The ClippingPrimitive will remove the destroyed Renderer from its registry without throwing a MissingReferenceException.
My setup
- Unity Version 2021.2.13f1
- MRTK Version 2.8.0
Target platform
- HoloLens 2
Additional context
Currently, the code that is checking whether renderer == null (line 374 in ClippingPriimitive.cs) will trigger the RemoveRenderer() method call which will in turn call the AquireMaterials() method - and the AquireMaterials() method assumes that the renderer has not been destroyed. So in essence: if the renderer is destroyed, we will call some code that requires that the renderer is not destroyed.
Alternatively it could be argued that it is the user's responsibility to always manually remove any registered Renderers from the ClippingPrimitive by calling RemoveRenderer() before a GameObject with a registered Renderer is being destroyed. But then, we should probably remove the code that tries to automatically handle the case where renderer == null.