fix: crash occurs when too many vertices are rendered

pull/289/head
mob-sakai 2023-08-14 15:33:19 +09:00
parent 52f2ef1f24
commit 723a04d0cf
1 changed files with 20 additions and 7 deletions

View File

@ -49,7 +49,7 @@ namespace Coffee.UIExtensions
return false; return false;
} }
} }
private Rect rootCanvasRect private Rect rootCanvasRect
{ {
get get
@ -116,7 +116,7 @@ namespace Coffee.UIExtensions
var modifiedMaterial = base.GetModifiedMaterial(baseMaterial); var modifiedMaterial = base.GetModifiedMaterial(baseMaterial);
// //
var texture = mainTexture; var texture = mainTexture;
if (texture == null && _parent.m_AnimatableProperties.Length == 0) if (texture == null && _parent.m_AnimatableProperties.Length == 0)
{ {
@ -276,6 +276,19 @@ namespace Coffee.UIExtensions
{ {
s_CombineInstances[0].mesh.Clear(false); s_CombineInstances[0].mesh.Clear(false);
} }
// Too many vertices to render.
if (65535 <= s_CombineInstances[0].mesh.vertexCount)
{
s_CombineInstances[0].mesh.Clear(false);
UnityEngine.Debug.LogErrorFormat(this,
"Too many vertices to render. index={0}, isTrail={1}, vertexCount={2}(>=65535)",
_index,
_isTrail,
s_CombineInstances[0].mesh.vertexCount
);
s_CombineInstances[0].mesh.Clear(false);
}
Profiler.EndSample(); Profiler.EndSample();
// Combine mesh to transform. ([ParticleSystem local ->] world -> renderer local) // Combine mesh to transform. ([ParticleSystem local ->] world -> renderer local)
@ -388,12 +401,12 @@ namespace Coffee.UIExtensions
protected override void UpdateGeometry() protected override void UpdateGeometry()
{ {
} }
public override void Cull(Rect clipRect, bool validRect) public override void Cull(Rect clipRect, bool validRect)
{ {
var cull = _lastBounds.extents == Vector3.zero || !validRect || !clipRect.Overlaps(rootCanvasRect, true); var cull = _lastBounds.extents == Vector3.zero || !validRect || !clipRect.Overlaps(rootCanvasRect, true);
if (canvasRenderer.cull == cull) return; if (canvasRenderer.cull == cull) return;
canvasRenderer.cull = cull; canvasRenderer.cull = cull;
UISystemProfilerApi.AddMarker("MaskableGraphic.cullingChanged", this); UISystemProfilerApi.AddMarker("MaskableGraphic.cullingChanged", this);
onCullStateChanged.Invoke(cull); onCullStateChanged.Invoke(cull);
@ -500,14 +513,14 @@ namespace Coffee.UIExtensions
? Time.unscaledDeltaTime ? Time.unscaledDeltaTime
: Time.deltaTime; : Time.deltaTime;
// Prewarm: // Prewarm:
if (0 < deltaTime && _prewarm) if (0 < deltaTime && _prewarm)
{ {
deltaTime += main.duration; deltaTime += main.duration;
_prewarm = false; _prewarm = false;
} }
// Emitted particles found. // Emitted particles found.
if (_prevParticleCount != _particleSystem.particleCount) if (_prevParticleCount != _particleSystem.particleCount)
{ {
var size = _particleSystem.particleCount; var size = _particleSystem.particleCount;
@ -593,4 +606,4 @@ namespace Coffee.UIExtensions
s_Mpb.Clear(); s_Mpb.Clear();
} }
} }
} }