Demigiant / dotween

A Unity C# animation engine. HOTween v2
http://dotween.demigiant.com
Other
2.33k stars 348 forks source link

Error in RemoveActiveTween (toActiveDefaultTween < 0). #587

Open choijaeyoung9 opened 2 years ago

choijaeyoung9 commented 2 years ago

Not sure if this is the right place to post this, but the error message was saying that it would be awesome if a log would be sent. I'm on 1.2.632 / 1.0.310 version, which seems to be the latest version according to "Check Updates" button.

Capture_Dotween

Disk.cs.115 and the relevant code is as follows:

    private Sequence diskTween;
    private Sequence spellTween;

    public void Awake()
    {
        rectTransform = GetComponent<RectTransform>();
        heatImage = transform.GetChild(0).GetComponent<Image>();
        fillImage = transform.GetChild(1).GetComponent<Image>();
        diskImage = transform.GetChild(2).GetComponent<Image>();
        spellImage = transform.GetChild(3).GetComponent<Image>();
        colorOfHeat = heatImage.color;

        diskTween = DOTween.Sequence();
        diskTween.Insert(0, diskImage.DOColor(Color.white, 0.6f).From(Color.green));
        diskTween.Insert(0, diskImage.rectTransform.DOScale(1.35f, 0.4f));
        diskTween.Insert(0.4f, diskImage.rectTransform.DOScale(0.75f, 0.1f));
        diskTween.Insert(0.5f, diskImage.rectTransform.DOScale(1f, 0.1f));

        spellTween = DOTween.Sequence();
        spellTween.Append(spellImage.rectTransform.DOScale(1.2f, 0.3f));
        spellTween.Append(spellImage.rectTransform.DOScale(0.75f, 0.1f));
        spellTween.Append(spellImage.rectTransform.DOScale(1f, 0.1f));
    }

    public void OnDestroy()
    {
        StopAllCoroutines();

        diskTween.Kill();
        spellTween.Kill(); // <=== this is line 115.
    }

I should note that the autokill tween is turned off on my project. So, I would use diskTween.Restart() or spellTween.Restart() somewhere else in the code to do the tweens. Also, I failed to capture it, but the log error message was "Some objects were not cleaned up when closing the scene. (Did you spawn new GameObjects from OnDestroy?)". Which was really weird since I do not instantiate or spawn a unity object on any of my codes on OnDestroy.

This particular message appeared as I was exiting from the play mode into the editor mode. The game objects that had Disk.cs attached were being destroyed by the editor, and I'm guessing that's when these message popped up. I tried to reproduce the error by loading up the same scene with the same items-disks-, but I failed to reproduce it despite my multiple attempts. So only a capture of that error message is all I have. I hope it helps.

j1mmie commented 1 year ago

We're also receiving these errors occasionally, but I don't have great visibility into them (for now) because I'm receiving them via error logs from live players. I need to add better debugging / logging, etc.

Interestingly, they seem to coincide with network hiccups in my multiplayer game. Very strange IMO - I'm not sure how they're related, except that maybe once the network clears up there is a queue of requests processed all at once, and therefore many new tweens initialized.

I have also turned off autokill.

I also occasionally see warnings that Max Tweens capacity has been exceeded.

Max Tweens reached: capacity has automatically been increased from 200/50 to 500/50. Use DOTween.SetTweensCapacity to set it manually at startup

I haven't explicitly seen these warnings coincide, but I wonder if there is some correlation. Like, the pool gets increased at the same moment a tween tries to remove itself from the queue. Maybe that results in a miss

Any help on tracking this down would be much appreciated

Demigiant commented 1 year ago

Ahoy, could you check if this updated version 1.2.696 fixes it? I just managed to reproduce it a few days ago and it's probably the same issue.

j1mmie commented 1 year ago

Ahoy, could you check if this updated version 1.2.696 fixes it? I just managed to reproduce it a few days ago and it's probably the same issue.

That’s great news, ill look into it. I won’t know for a few weeks if my users are running into the problem. If they do I’ll try to isolate a repro case and send it over. Thanks for the quick follow up

j1mmie commented 1 year ago

@Demigiant - Hi Daniele, I found a repro case and have more info. The error still occurs in 1.2.696. Here's a stack trace:

IndexOutOfRangeException: Index was outside the bounds of the array.
DG.Tweening.Core.TweenManager.RemoveActiveTween (DG.Tweening.Tween t) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/TweenManager.cs:1181)
DG.Tweening.Core.TweenManager.Despawn (DG.Tweening.Tween t, System.Boolean modifyActiveLists) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/TweenManager.cs:236)
DG.Tweening.Core.TweenManager.DespawnActiveTweens (System.Collections.Generic.List`1[T] tweens) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/TweenManager.cs:1167)
DG.Tweening.Core.TweenManager.Update (DG.Tweening.UpdateType updateType, System.Single deltaTime, System.Single independentTime) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/TweenManager.cs:496)
DG.Tweening.Core.DOTweenComponent.Update () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/DOTweenComponent.cs:75)

But I've learned that this error only comes after another series of errors that are caused by my own code.

In my case, I am accidentally tweening a value on a GameObject that has been destroyed. As a result, the tween spits outs this error on every frame during the tween's lifecycle:

MissingReferenceException: The object of type 'Image' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEngine.EventSystems.UIBehaviour.IsActive () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/UIBehaviour.cs:28)
UnityEngine.UI.Graphic.SetVerticesDirty () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Graphic.cs:291)
UnityEngine.UI.Image.set_fillAmount (System.Single value) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Image.cs:485)
ProgressBarAnimations+<>c__DisplayClass20_0.<TweenFill>b__2 () (at Assets/Scripts/UI/Components/ProgressBar/ProgressBarAnimations.cs:166)
DG.Tweening.Tween.OnTweenCallback (DG.Tweening.TweenCallback callback, DG.Tweening.Tween t) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Tween.cs:308)
DG.Tweening.Tween.DoGoto (DG.Tweening.Tween t, System.Single toPosition, System.Int32 toCompletedLoops, DG.Tweening.Core.Enums.UpdateMode updateMode) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Tween.cs:270)
DG.Tweening.Core.TweenManager.Update (DG.Tweening.Tween t, System.Single deltaTime, System.Single independentTime, System.Boolean isSingleTweenManualUpdate) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/TweenManager.cs:569)
DG.Tweening.Core.TweenManager.Update (DG.Tweening.UpdateType updateType, System.Single deltaTime, System.Single independentTime) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/TweenManager.cs:417)
DG.Tweening.Core.DOTweenComponent.Update () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/DOTweenComponent.cs:75)

That makes sense. However, if any other tween is scheduled during this time, it is bound to fail. And it will trigger the RemoveActiveTween error as well.

If this is not clear, I can try to create a project that illustrates the problem more clearly. Let me know. Thank you

Demigiant commented 1 year ago

Ah, but you're not using safe mode, am I right? Because that should take care of it, but otherwise if there's other errors that cause DOTween to crash I'm afraid I don't have much control over that, as long as I don't catch them on time with safe mode. Let me know!

j1mmie commented 1 year ago

Correct @Demigiant, we’re not using Safe Mode. I didn’t know what it was, but I’m reading about it now. Is there any performance impact with safe mode?

Demigiant commented 1 year ago

There's basically no performance impact. What it does is adding try-catches in specific points (much faster than checking for null in lots of them) to catch overall errors because of tween targets becoming null or things like that, and then it destroys those tweens automatically

j1mmie commented 1 year ago

Thanks for the info. I’ll try with safe mode on

rhys-vdw commented 1 year ago

I'm getting these errors in v1.2.632 when exiting play mode. I believe they are linked to the DOTween singleton object not being properly cleaned up when exiting play mode.

Similar to @choijaeyoung9, my OnDestroy method contains a call to DOTween.Kill. My guess is that this is because the TutorialController.OnDestroy is being called from an async method that overruns play mode, possibly being called after DOTween object is destroyed, causing it to be lazily recreated. When I re-enter play mode DOTween fails to work, presumably because some static reference to this bad object remains.

That's all guesses though. I'm going to try to update to latest to see if the issue goes away, I just wanted to leave this info here as requested in the warning @Demigiant.

I'm seeing this quite regularly so hopefully I'll be able to report soon if the issue is resolved.

image

⚠️ 1

DOTWEEN ► Error in RemoveActiveTween (totActiveDefaultTweens < 0). It's been taken care of so no problems, but Daniele (DOTween's author) is trying to pinpoint it (it's very rare and he can't reproduce it) so it would be awesome if you could reproduce this log in a sample project and send it to him. Or even just write him the complete log that was generated by this message. Fixing this would make DOTween slightly faster. Thanks.
UnityEngine.Debug:LogWarning (object)
DG.Tweening.Core.Debugger:LogWarning (object,DG.Tweening.Tween)
DG.Tweening.Core.Debugger:LogRemoveActiveTweenError (string,DG.Tweening.Tween)
DG.Tweening.Core.TweenManager:RemoveActiveTween (DG.Tweening.Tween)
DG.Tweening.Core.TweenManager:Despawn (DG.Tweening.Tween,bool)
DG.Tweening.TweenExtensions:Kill (DG.Tweening.Tween,bool)
EffortStar.DOTweenUtility:Kill (DG.Tweening.Tween&,bool) (at Assets/_Game/Scripts/Utility/DOTweenUtility.cs:50)
EffortStar.TutorialController:OnDestroy () (at Assets/_Game/Scripts/TutorialController.cs:74)

⚠️ 2

DOTWEEN ► Error in RemoveActiveTween (totActiveTweens < 0). It's been taken care of so no problems, but Daniele (DOTween's author) is trying to pinpoint it (it's very rare and he can't reproduce it) so it would be awesome if you could reproduce this log in a sample project and send it to him. Or even just write him the complete log that was generated by this message. Fixing this would make DOTween slightly faster. Thanks.
UnityEngine.Debug:LogWarning (object)
DG.Tweening.Core.Debugger:LogWarning (object,DG.Tweening.Tween)
DG.Tweening.Core.Debugger:LogRemoveActiveTweenError (string,DG.Tweening.Tween)
DG.Tweening.Core.TweenManager:RemoveActiveTween (DG.Tweening.Tween)
DG.Tweening.Core.TweenManager:Despawn (DG.Tweening.Tween,bool)
DG.Tweening.TweenExtensions:Kill (DG.Tweening.Tween,bool)
EffortStar.DOTweenUtility:Kill (DG.Tweening.Tween&,bool) (at Assets/_Game/Scripts/Utility/DOTweenUtility.cs:50)
EffortStar.TutorialController:OnDestroy () (at Assets/_Game/Scripts/TutorialController.cs:74)

⚠️ 3

DOTWEEN ► Error in RemoveActiveTween (totActiveSequences < 0). It's been taken care of so no problems, but Daniele (DOTween's author) is trying to pinpoint it (it's very rare and he can't reproduce it) so it would be awesome if you could reproduce this log in a sample project and send it to him. Or even just write him the complete log that was generated by this message. Fixing this would make DOTween slightly faster. Thanks.
UnityEngine.Debug:LogWarning (object)
DG.Tweening.Core.Debugger:LogWarning (object,DG.Tweening.Tween)
DG.Tweening.Core.Debugger:LogRemoveActiveTweenError (string,DG.Tweening.Tween)
DG.Tweening.Core.TweenManager:RemoveActiveTween (DG.Tweening.Tween)
DG.Tweening.Core.TweenManager:Despawn (DG.Tweening.Tween,bool)
DG.Tweening.TweenExtensions:Kill (DG.Tweening.Tween,bool)
EffortStar.DOTweenUtility:Kill (DG.Tweening.Tween&,bool) (at Assets/_Game/Scripts/Utility/DOTweenUtility.cs:50)
EffortStar.TutorialController:OnDestroy () (at Assets/_Game/Scripts/TutorialController.cs:74)

4

Some objects were not cleaned up when closing the scene. (Did you spawn new GameObjects from OnDestroy?)
The following scene GameObjects were found:
[DOTween]
rhys-vdw commented 1 year ago

I get the same issue after upgrading, exact same sequence of errors. When I enter play mode again [DOTween] object still exists and is not in DDOL section:

image

Tween no longer work until I discard changes to the scene and play again.

Demigiant commented 1 year ago

Woah, this is... different. I've never seen it happening and I'm not sure how to reproduce it. Could you create a sample barebone project that replicates and attach it here?

rhys-vdw commented 1 year ago

I would like to. As yet I haven't investigated the exact cause of the issue, but if I can isolate it I can try!

rhys-vdw commented 1 year ago

Hey @Demigiant, just wanted to update this thread to say that it seems these two issues are unrelated (or at least don't always coincide). I haven't seen the "Error in RemoveActiveTween" warning since my previous comment, but am fairly consistently getting the lingering DOTween object. (Yet to produce a minimal reproduction.) I will open another issue when I get a chance to dig into the issue.

Demigiant commented 1 year ago

Thank you! I would expect the lingering DOTween object to cause all kinds of issues, though I can't understand why it's happening to you 😬