better null checking

This commit is contained in:
Andrew Cassidy 2022-10-31 00:05:31 -07:00
parent ece9d959fd
commit d3388a4dad

View File

@ -577,20 +577,11 @@ namespace ConformalDecals {
public void Render(Camera camera) { public void Render(Camera camera) {
if (!_isAttached) return; if (!_isAttached) return;
try { // render on each target object
// render on each target object foreach (var target in _targets) {
foreach (var target in _targets) { if (ReferenceEquals(target.target, null)) _targets.Remove(target);
target.Render(_decalMaterial, part.mpb, camera); else target.Render(_decalMaterial, part.mpb, camera);
}
} catch (NullReferenceException) {
// catch any NREs and purge null transforms from the target list
// comparing Transform to null is expensive, but a try-catch block is much cheaper
foreach (var target in _targets) {
if (target.target == null) {
_targets.Remove(target);
}
}
} }
} }
} }