1
0
mirror of https://github.com/Cardidi/dotween-upm-fork.git synced 2025-12-21 01:36:05 +08:00

Added IndexOutOfRange safety checks, hoping someone one day will be able to reproduce it for me so I can fix it

This commit is contained in:
Demigiant 2019-02-09 10:59:43 +01:00
parent 66a296f34f
commit 3da9f70ce1
24 changed files with 57 additions and 27 deletions

View File

@ -2452,7 +2452,7 @@
Default is -999 so avoid using an ID like that or it will capture all unset intIds</summary> Default is -999 so avoid using an ID like that or it will capture all unset intIds</summary>
</member> </member>
<member name="F:DG.Tweening.Tween.target"> <member name="F:DG.Tweening.Tween.target">
<summary>Tween target (usable for filtering with DOTween static methods). Automatically set by tween creation shorcuts</summary> <summary>Tween target (usable for filtering with DOTween static methods). Automatically set by tween creation shortcuts</summary>
</member> </member>
<member name="F:DG.Tweening.Tween.onPlay"> <member name="F:DG.Tweening.Tween.onPlay">
<summary>Called when the tween is set in a playing state, after any eventual delay. <summary>Called when the tween is set in a playing state, after any eventual delay.

View File

@ -1,6 +1,6 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 1b9c6b17aec073847a9d34c432a148ec guid: 1b9c6b17aec073847a9d34c432a148ec
timeCreated: 1544961652 timeCreated: 1548936985
licenseType: Pro licenseType: Pro
TextScriptImporter: TextScriptImporter:
userData: userData:

View File

@ -1,6 +1,6 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 56bca508bd08a4f44a507f17e7577afb guid: 56bca508bd08a4f44a507f17e7577afb
timeCreated: 1544961640 timeCreated: 1548936971
licenseType: Pro licenseType: Pro
DefaultImporter: DefaultImporter:
userData: userData:

View File

@ -1,6 +1,6 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: c7602d66796c87a4fac3013913374c07 guid: c7602d66796c87a4fac3013913374c07
timeCreated: 1544961644 timeCreated: 1548936979
licenseType: Pro licenseType: Pro
PluginImporter: PluginImporter:
serializedVersion: 2 serializedVersion: 2

View File

@ -1,6 +1,6 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: d3e15b806a8368742ba6f10e794d7b76 guid: d3e15b806a8368742ba6f10e794d7b76
timeCreated: 1545441841 timeCreated: 1549566641
licenseType: Pro licenseType: Pro
TextureImporter: TextureImporter:
fileIDToRecycleName: {} fileIDToRecycleName: {}

View File

@ -35,7 +35,9 @@ namespace DG.Tweening.Core
{ {
if (DOTween.instance == null) DOTween.instance = this; if (DOTween.instance == null) DOTween.instance = this;
else { else {
Debugger.LogWarning("Duplicate DOTweenComponent instance found in scene: destroying it"); if (Debugger.logPriority >= 1) {
Debugger.LogWarning("Duplicate DOTweenComponent instance found in scene: destroying it");
}
Destroy(this.gameObject); Destroy(this.gameObject);
return; return;
} }

View File

@ -67,9 +67,14 @@ namespace DG.Tweening.Core
LogWarning(string.Format("This material doesn't have a {0} property", propertyName)); LogWarning(string.Format("This material doesn't have a {0} property", propertyName));
} }
public static void LogRemoveActiveTweenError(string propertyName) public static void LogRemoveActiveTweenError(string errorInfo)
{ {
Log(string.Format("Error in RemoveActiveTween.{0}. It's been taken care of so no problems, but Daniele (DOTween's author) is trying to pinpoint it and 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.", propertyName)); LogWarning(string.Format("Error in RemoveActiveTween ({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.", errorInfo));
}
public static void LogAddActiveTweenError(string errorInfo)
{
LogWarning(string.Format("Error in AddActiveTween ({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.", errorInfo));
} }
public static void SetLogPriority(LogBehaviour logBehaviour) public static void SetLogPriority(LogBehaviour logBehaviour)

View File

@ -877,6 +877,16 @@ namespace DG.Tweening.Core
{ {
if (_requiresActiveReorganization) ReorganizeActiveTweens(); if (_requiresActiveReorganization) ReorganizeActiveTweens();
// Safety check (IndexOutOfRangeException)
if (totActiveTweens < 0) {
Debugger.LogAddActiveTweenError("totActiveTweens < 0");
totActiveTweens = 0;
}
// else if (totActiveTweens > _activeTweens.Length - 1) {
// Debugger.LogError("AddActiveTween: totActiveTweens > _activeTweens capacity. This should never ever happen. Please report it with instructions on how to reproduce it");
// return;
// }
t.active = true; t.active = true;
t.updateType = DOTween.defaultUpdateType; t.updateType = DOTween.defaultUpdateType;
t.isIndependentUpdate = DOTween.defaultTimeScaleIndependent; t.isIndependentUpdate = DOTween.defaultTimeScaleIndependent;
@ -957,36 +967,40 @@ namespace DG.Tweening.Core
_activeTweens[index] = null; _activeTweens[index] = null;
if (t.updateType == UpdateType.Normal) { if (t.updateType == UpdateType.Normal) {
// Safety check (IndexOutOfRangeException)
if (totActiveDefaultTweens > 0) { if (totActiveDefaultTweens > 0) {
totActiveDefaultTweens--; totActiveDefaultTweens--;
hasActiveDefaultTweens = totActiveDefaultTweens > 0; hasActiveDefaultTweens = totActiveDefaultTweens > 0;
} else { } else {
Debugger.LogRemoveActiveTweenError("totActiveDefaultTweens"); Debugger.LogRemoveActiveTweenError("totActiveDefaultTweens < 0");
} }
} else { } else {
switch (t.updateType) { switch (t.updateType) {
case UpdateType.Fixed: case UpdateType.Fixed:
// Safety check (IndexOutOfRangeException)
if (totActiveFixedTweens > 0) { if (totActiveFixedTweens > 0) {
totActiveFixedTweens--; totActiveFixedTweens--;
hasActiveFixedTweens = totActiveFixedTweens > 0; hasActiveFixedTweens = totActiveFixedTweens > 0;
} else { } else {
Debugger.LogRemoveActiveTweenError("totActiveFixedTweens"); Debugger.LogRemoveActiveTweenError("totActiveFixedTweens < 0");
} }
break; break;
case UpdateType.Late: case UpdateType.Late:
// Safety check (IndexOutOfRangeException)
if (totActiveLateTweens > 0) { if (totActiveLateTweens > 0) {
totActiveLateTweens--; totActiveLateTweens--;
hasActiveLateTweens = totActiveLateTweens > 0; hasActiveLateTweens = totActiveLateTweens > 0;
} else { } else {
Debugger.LogRemoveActiveTweenError("totActiveLateTweens"); Debugger.LogRemoveActiveTweenError("totActiveLateTweens < 0");
} }
break; break;
default: default:
// Safety check (IndexOutOfRangeException)
if (totActiveManualTweens > 0) { if (totActiveManualTweens > 0) {
totActiveManualTweens--; totActiveManualTweens--;
hasActiveManualTweens = totActiveManualTweens > 0; hasActiveManualTweens = totActiveManualTweens > 0;
} else { } else {
Debugger.LogRemoveActiveTweenError("totActiveManualTweens"); Debugger.LogRemoveActiveTweenError("totActiveManualTweens < 0");
} }
break; break;
} }
@ -995,17 +1009,20 @@ namespace DG.Tweening.Core
hasActiveTweens = totActiveTweens > 0; hasActiveTweens = totActiveTweens > 0;
if (t.tweenType == TweenType.Tweener) totActiveTweeners--; if (t.tweenType == TweenType.Tweener) totActiveTweeners--;
else totActiveSequences--; else totActiveSequences--;
// Safety check (IndexOutOfRangeException)
if (totActiveTweens < 0) { if (totActiveTweens < 0) {
totActiveTweens = 0; totActiveTweens = 0;
Debugger.LogRemoveActiveTweenError("totActiveTweens"); Debugger.LogRemoveActiveTweenError("totActiveTweens < 0");
} }
// Safety check (IndexOutOfRangeException)
if (totActiveTweeners < 0) { if (totActiveTweeners < 0) {
totActiveTweeners = 0; totActiveTweeners = 0;
Debugger.LogRemoveActiveTweenError("totActiveTweeners"); Debugger.LogRemoveActiveTweenError("totActiveTweeners < 0");
} }
// Safety check (IndexOutOfRangeException)
if (totActiveSequences < 0) { if (totActiveSequences < 0) {
totActiveSequences = 0; totActiveSequences = 0;
Debugger.LogRemoveActiveTweenError("totActiveSequences"); Debugger.LogRemoveActiveTweenError("totActiveSequences < 0");
} }
} }

View File

@ -32,7 +32,7 @@ namespace DG.Tweening
public class DOTween public class DOTween
{ {
/// <summary>DOTween's version</summary> /// <summary>DOTween's version</summary>
public static readonly string Version = "1.2.165"; // Last version before modules: 1.1.755 public static readonly string Version = "1.2.166"; // Last version before modules: 1.1.755
/////////////////////////////////////////////// ///////////////////////////////////////////////
// Options //////////////////////////////////// // Options ////////////////////////////////////

View File

@ -31,7 +31,7 @@ namespace DG.Tweening
/// <summary>Int ID (usable for filtering with DOTween static methods). 4X faster than using an object id, 2X faster than using a string id. /// <summary>Int ID (usable for filtering with DOTween static methods). 4X faster than using an object id, 2X faster than using a string id.
/// Default is -999 so avoid using an ID like that or it will capture all unset intIds</summary> /// Default is -999 so avoid using an ID like that or it will capture all unset intIds</summary>
public int intId = -999; public int intId = -999;
/// <summary>Tween target (usable for filtering with DOTween static methods). Automatically set by tween creation shorcuts</summary> /// <summary>Tween target (usable for filtering with DOTween static methods). Automatically set by tween creation shortcuts</summary>
public object target; // Automatically set by DO shortcuts using SetTarget extension. Also used during Tweener.DoStartup in some special cases public object target; // Automatically set by DO shortcuts using SetTarget extension. Also used during Tweener.DoStartup in some special cases
// Update type and eventual independence (changed via TweenManager.SetUpdateType) // Update type and eventual independence (changed via TweenManager.SetUpdateType)
internal UpdateType updateType; internal UpdateType updateType;
@ -280,9 +280,11 @@ namespace DG.Tweening
try { try {
callback(); callback();
} catch (Exception e) { } catch (Exception e) {
Debugger.LogWarning(string.Format( if (Debugger.logPriority >= 1) {
"An error inside a tween callback was silently taken care of ({0}) ► {1}\n\n{2}\n\n", e.TargetSite, e.Message, e.StackTrace Debugger.LogWarning(string.Format(
)); "An error inside a tween callback was silently taken care of ({0}) ► {1}\n\n{2}\n\n", e.TargetSite, e.Message, e.StackTrace
));
}
return false; // Callback error return false; // Callback error
} }
} else callback(); } else callback();
@ -294,9 +296,11 @@ namespace DG.Tweening
try { try {
callback(param); callback(param);
} catch (Exception e) { } catch (Exception e) {
Debugger.LogWarning(string.Format( if (Debugger.logPriority >= 1) {
"An error inside a tween callback was silently taken care of ({0}) ► {1}", e.TargetSite, e.Message Debugger.LogWarning(string.Format(
)); "An error inside a tween callback was silently taken care of ({0}) ► {1}", e.TargetSite, e.Message
));
}
return false; // Callback error return false; // Callback error
} }
} else callback(param); } else callback(param);

View File

@ -134,9 +134,11 @@ namespace DG.Tweening
try { try {
t.startValue = t.tweenPlugin.ConvertToStartValue(t, t.getter()); t.startValue = t.tweenPlugin.ConvertToStartValue(t, t.getter());
} catch (Exception e) { } catch (Exception e) {
Debugger.LogWarning(string.Format( if (Debugger.logPriority >= 1) {
"Tween startup failed (NULL target/property - {0}): the tween will now be killed ► {1}", e.TargetSite, e.Message Debugger.LogWarning(string.Format(
)); "Tween startup failed (NULL target/property - {0}): the tween will now be killed ► {1}", e.TargetSite, e.Message
));
}
return false; // Target/field doesn't exist: kill tween return false; // Target/field doesn't exist: kill tween
} }
} else t.startValue = t.tweenPlugin.ConvertToStartValue(t, t.getter()); } else t.startValue = t.tweenPlugin.ConvertToStartValue(t, t.getter());

View File

@ -2452,7 +2452,7 @@
Default is -999 so avoid using an ID like that or it will capture all unset intIds</summary> Default is -999 so avoid using an ID like that or it will capture all unset intIds</summary>
</member> </member>
<member name="F:DG.Tweening.Tween.target"> <member name="F:DG.Tweening.Tween.target">
<summary>Tween target (usable for filtering with DOTween static methods). Automatically set by tween creation shorcuts</summary> <summary>Tween target (usable for filtering with DOTween static methods). Automatically set by tween creation shortcuts</summary>
</member> </member>
<member name="F:DG.Tweening.Tween.onPlay"> <member name="F:DG.Tweening.Tween.onPlay">
<summary>Called when the tween is set in a playing state, after any eventual delay. <summary>Called when the tween is set in a playing state, after any eventual delay.

Binary file not shown.