From 79354c444bc4d97b694c8e2adbf17f8232123eca Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 14 Dec 2021 13:42:31 +0100 Subject: [PATCH] fixed exception when elements get removed from their ui in Update --- MLEM.Ui/Elements/Element.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index 0b7dcd5..d27db6e 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -888,11 +888,13 @@ namespace MLEM.Ui.Elements { public virtual void Update(GameTime time) { this.System.InvokeOnElementUpdated(this, time); - foreach (var child in this.GetRelevantChildren()) + foreach (var child in this.GetRelevantChildren()) { if (child.System != null) child.Update(time); + } - this.System.Metrics.Updates++; + if (this.System != null) + this.System.Metrics.Updates++; } /// @@ -920,9 +922,12 @@ namespace MLEM.Ui.Elements { batch.Begin(SpriteSortMode.Deferred, blendState, samplerState, depthStencilState, null, effect, mat); } } + // draw content in custom begin call this.Draw(time, batch, alpha, blendState, samplerState, depthStencilState, effect, mat); - this.System.Metrics.Draws++; + if (this.System != null) + this.System.Metrics.Draws++; + if (customDraw) { // end our draw batch.End();