dotween icon indicating copy to clipboard operation
dotween copied to clipboard

Sequences silently hang execution if they contains a tween created on a null component

Open ehudros opened this issue 6 years ago • 6 comments

Sequences stop execution entirely without throwing an exception/warning when they reach a tween that was mistakenly created on a null object. Here's a simple repro:

SpriteRenderer nullRenderer = null;
SpriteRenderer validRenderer = GetComponentInChildren<SpriteRenderer>();

var seq = DOTween.Sequence();
// this fails silently, the tween has a null target
seq.Insert(0, nullRenderer.DOFade(1, 1));
// This never gets executed
seq.Insert(0.1, validRenderer.DOFade(0, 1));

It think it makes sense to throw an exception when you try to create a tween on a null object, or when such a tween is executed. Stoping the sequence from continuing to execute without notice has serious side effects.

ehudros avatar Apr 16 '18 10:04 ehudros

does it swallow the exception if safe mode is disabled? (see dotween settings)

krisrok avatar May 02 '18 09:05 krisrok

Nope, running without safe mode throws multiple exceptions:

NullReferenceException: Object reference not set to an instance of an object
DG.Tweening.ShortcutExtensions43+<>c__DisplayClass3_0.<DOFade>b__0 () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween43/ShortcutExtensions43.cs:84)
DG.Tweening.Tweener.DoStartup[Color,Color,ColorOptions] (DG.Tweening.Core.TweenerCore`3 t) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Tweener.cs:136)
DG.Tweening.Core.TweenerCore`3[UnityEngine.Color,UnityEngine.Color,DG.Tweening.Plugins.Options.ColorOptions].Startup () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/TweenerCore.cs:165)
DG.Tweening.Tween.DoGoto (DG.Tweening.Tween t, Single toPosition, Int32 toCompletedLoops, UpdateMode updateMode) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Tween.cs:182)
DG.Tweening.Core.TweenManager.Goto (DG.Tweening.Tween t, Single to, Boolean andPlay, UpdateMode updateMode) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/TweenManager.cs:565)
DG.Tweening.Sequence.ApplyInternalCycle (DG.Tweening.Sequence s, Single fromPos, Single toPos, UpdateMode updateMode, Boolean useInverse, Boolean prevPosIsInverse, Boolean multiCycleStep) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Sequence.cs:305)
DG.Tweening.Sequence.DoApplyTween (DG.Tweening.Sequence s, Single prevPosition, Int32 prevCompletedLoops, Int32 newCompletedSteps, Boolean useInversePosition, UpdateMode updateMode) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Sequence.cs:239)
DG.Tweening.Sequence.ApplyTween (Single prevPosition, Int32 prevCompletedLoops, Int32 newCompletedSteps, Boolean useInversePosition, UpdateMode updateMode, UpdateNotice updateNotice) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Sequence.cs:143)
DG.Tweening.Tween.DoGoto (DG.Tweening.Tween t, Single toPosition, Int32 toCompletedLoops, UpdateMode updateMode) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Tween.cs:238)
DG.Tweening.Core.TweenManager.Update (UpdateType updateType, Single deltaTime, Single independentTime) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/TweenManager.cs:391)
DG.Tweening.Core.DOTweenComponent.Update () (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/DOTweenComponent.cs:50)

It should probably throw a warning in safe mode though, like it does with regular runtime exceptions?

ehudros avatar May 02 '18 13:05 ehudros

as from what i've learned this is the expceted behaviour. safe-mode swallows exceptions whereas non-safe mode throws them.

but i guess you are right, you should not be able to make this mistake:

the extension methods (DOFade() in this case) should check for null and throw an ArgumentNullException. also, Sequence.Insert() should throw the same exception when adding a null reference. guess the same goes for Append() and others.

krisrok avatar May 02 '18 13:05 krisrok

Ahoy!

You are right, I should throw a warning instead of silently refusing to add the target to the Sequence. Will work on this tomorrow.

Demigiant avatar May 02 '18 15:05 Demigiant

Can confirm this behaviour on v1.2.632.

Note that nulling any part of the tween will make sequence insertion hang. For example, in the following snippet, either obj or data being null will hang.

var sequence = DOTween.Sequence();
sequence.Insert(0, obj.transform.DOMoveY(0, data.duration));

Even disabling silent mode won't throw a bug.

Reimirno avatar Apr 11 '23 03:04 Reimirno

Ahoy,

In DOTween Preferences (from the Utility Panel) you can choose what happens in these cases at the voice "On Nested Tween Failure": kill the whole Sequence or try to preserve it. It's weird that it doesn't throw a warning if you changed the log behavior though, I'm.going to investigate it

Demigiant avatar Apr 11 '23 07:04 Demigiant