taffyko / LCBetterSprayPaint

A mod for the game Lethal Company that improves its spray paint mechanic
MIT License
3 stars 3 forks source link

(BUG) Error Log Spam #24

Closed TheComicRelief closed 2 weeks ago

TheComicRelief commented 2 weeks ago

Mod spams error in console.

MrCatguy commented 2 weeks ago

same for me also spray preview doesn't work 20% of the time I've found (some rooms completely don't allow the preview)

notpeelz commented 2 weeks ago

I'm guessing this is the error being discussed:

[Error  : Unity Log] NullReferenceException
Stack trace:
SprayPaintItemExt.Update () (at D:/SteamLibrary/steamapps/common/Lethal Company/projects/BetterSprayPaint/src/SprayPaintItemExt.cs:151

https://github.com/taffyko/LCBetterSprayPaint/blob/e0237468545f9ce4e1a5fccdc6ce721006b54077/src/SprayPaintItemExt.cs#L151

This happens because Unity overloads the == operator to handle checking if the object was destroyed. Source: https://stackoverflow.com/a/72072517/1581233

This can be fixed by removing the null-propagating operator:

--- a/src/SprayPaintItemExt.cs
+++ b/src/SprayPaintItemExt.cs
@@ -148,7 +148,7 @@ public class SprayPaintItemExt: MonoBehaviour {
         var c = net.CurrentColor;
         var factor = (Mathf.Sin(Time.timeSinceLevelLoad * 6f) + 1f) * 0.2f + 0.2f;
         previewFadeFactor = Utils.Lexp(previewFadeFactor, active ? 1f : 0f, 15f * Time.deltaTime);
-        if (previewDecal?.gameObject != null && previewDecal.material != null) {
+        if (previewDecal != null && previewDecal.gameObject != null && previewDecal.material != null) {
             previewDecal.material.color = new Color(
                 Mathf.Lerp(c.r, Math.Min(c.r + 0.35f, 1f), factor),
                 Mathf.Lerp(c.g, Math.Min(c.g + 0.35f, 1f), factor),