mirror of
https://github.com/Cardidi/dotween-upm-fork.git
synced 2025-12-21 01:36:05 +08:00
Fixed rare but randomly happening IndexOutOfRange exception (finally, wohoo!)
This commit is contained in:
parent
2d562c4829
commit
a7458f0445
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
61
UnityTests.Unity5/Assets/_Tests/Bugs/IndexOutOfRangeHell.cs
Normal file
61
UnityTests.Unity5/Assets/_Tests/Bugs/IndexOutOfRangeHell.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using DG.Tweening;
|
||||||
|
|
||||||
|
public class IndexOutOfRangeHell : BrainBase
|
||||||
|
{
|
||||||
|
public GameObject prefab;
|
||||||
|
public Transform container;
|
||||||
|
|
||||||
|
List<Transform> ts;
|
||||||
|
|
||||||
|
IEnumerator Start()
|
||||||
|
{
|
||||||
|
ts = new List<Transform>();
|
||||||
|
while (true) {
|
||||||
|
if (ts.Count < 1000) {
|
||||||
|
Debug.Log(Time.frameCount + " Creating tweens");
|
||||||
|
SpawnObjectsAndTweens(1000);
|
||||||
|
}
|
||||||
|
if (Time.frameCount % 100 == 0) {
|
||||||
|
Debug.Log("<color=#00FF00>Clearing DOTween</color>");
|
||||||
|
foreach (Transform t in ts) Destroy(t.gameObject);
|
||||||
|
ts.Clear();
|
||||||
|
DOTween.Clear(true);
|
||||||
|
}
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpawnObjectsAndTweens(int tot)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < tot; ++i) {
|
||||||
|
GameObject go = Instantiate(prefab) as GameObject;
|
||||||
|
go.transform.position = RandomV3();
|
||||||
|
go.transform.parent = container;
|
||||||
|
go.GetComponent<Renderer>().enabled = false;
|
||||||
|
Transform t = go.transform;
|
||||||
|
ts.Add(t);
|
||||||
|
if (i % 2 == 0) {
|
||||||
|
// Tweener
|
||||||
|
t.DOMove(RandomV3(), Random.Range(0.1f, 1f)).OnComplete(()=> {
|
||||||
|
ts.Remove(t);
|
||||||
|
Destroy(t.gameObject);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Sequence
|
||||||
|
DOTween.Sequence().Append(t.DOMove(RandomV3(), Random.Range(0.1f, 1f))).OnComplete(()=> {
|
||||||
|
ts.Remove(t);
|
||||||
|
Destroy(t.gameObject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 RandomV3()
|
||||||
|
{
|
||||||
|
const float range = 7;
|
||||||
|
return new Vector3(Random.Range(-range,range), Random.Range(-range,range), Random.Range(-range,range));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e8e1d53ce928f164c802c0d586a0ab9f
|
||||||
|
timeCreated: 1427113863
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
BIN
UnityTests.Unity5/Assets/_Tests/Bugs/IndexOutOfRangeHell.unity
Normal file
BIN
UnityTests.Unity5/Assets/_Tests/Bugs/IndexOutOfRangeHell.unity
Normal file
Binary file not shown.
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 994c5705c1d317845a93116b134051cd
|
||||||
|
timeCreated: 1427113851
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Binary file not shown.
@ -15,7 +15,7 @@ namespace DG.Tweening.Core
|
|||||||
{
|
{
|
||||||
const int _DefaultMaxTweeners = 200;
|
const int _DefaultMaxTweeners = 200;
|
||||||
const int _DefaultMaxSequences = 50;
|
const int _DefaultMaxSequences = 50;
|
||||||
const string _MaxTweensReached = "Max Tweens reached: capacity will be automatically increased from #0 to #1. Use DOTween.SetTweensCapacity to set it manually at startup";
|
const string _MaxTweensReached = "Max Tweens reached: capacity has automatically been increased from #0 to #1. Use DOTween.SetTweensCapacity to set it manually at startup";
|
||||||
|
|
||||||
internal static int maxActive = _DefaultMaxTweeners; // Always equal to maxTweeners
|
internal static int maxActive = _DefaultMaxTweeners; // Always equal to maxTweeners
|
||||||
internal static int maxTweeners = _DefaultMaxTweeners; // Always >= maxSequences
|
internal static int maxTweeners = _DefaultMaxTweeners; // Always >= maxSequences
|
||||||
@ -81,12 +81,14 @@ namespace DG.Tweening.Core
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Increase capacity in case max number of Tweeners has already been reached, then continue
|
// Increase capacity in case max number of Tweeners has already been reached, then continue
|
||||||
if (totTweeners >= maxTweeners) {
|
if (totTweeners >= maxTweeners - 1) {
|
||||||
if (Debugger.logPriority >= 1) Debugger.LogWarning(_MaxTweensReached
|
int prevMaxTweeners = maxTweeners;
|
||||||
.Replace("#0", maxTweeners + "/" + maxSequences)
|
int prevMaxSequences = maxSequences;
|
||||||
.Replace("#1", (maxTweeners + _DefaultMaxTweeners) + "/" + maxSequences)
|
|
||||||
);
|
|
||||||
IncreaseCapacities(CapacityIncreaseMode.TweenersOnly);
|
IncreaseCapacities(CapacityIncreaseMode.TweenersOnly);
|
||||||
|
if (Debugger.logPriority >= 1) Debugger.LogWarning(_MaxTweensReached
|
||||||
|
.Replace("#0", prevMaxTweeners + "/" + prevMaxSequences)
|
||||||
|
.Replace("#1", maxTweeners + "/" + maxSequences)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Not found: create new TweenerController
|
// Not found: create new TweenerController
|
||||||
@ -108,12 +110,14 @@ namespace DG.Tweening.Core
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
// Increase capacity in case max number of Sequences has already been reached, then continue
|
// Increase capacity in case max number of Sequences has already been reached, then continue
|
||||||
if (totSequences >= maxSequences) {
|
if (totSequences >= maxSequences - 1) {
|
||||||
if (Debugger.logPriority >= 1) Debugger.LogWarning(_MaxTweensReached
|
int prevMaxTweeners = maxTweeners;
|
||||||
.Replace("#0", maxTweeners + "/" + maxSequences)
|
int prevMaxSequences = maxSequences;
|
||||||
.Replace("#1", maxTweeners + "/" + (maxSequences + _DefaultMaxSequences))
|
|
||||||
);
|
|
||||||
IncreaseCapacities(CapacityIncreaseMode.SequencesOnly);
|
IncreaseCapacities(CapacityIncreaseMode.SequencesOnly);
|
||||||
|
if (Debugger.logPriority >= 1) Debugger.LogWarning(_MaxTweensReached
|
||||||
|
.Replace("#0", prevMaxTweeners + "/" + prevMaxSequences)
|
||||||
|
.Replace("#1", maxTweeners + "/" + maxSequences)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// Not found: create new Sequence
|
// Not found: create new Sequence
|
||||||
s = new Sequence();
|
s = new Sequence();
|
||||||
@ -802,20 +806,24 @@ namespace DG.Tweening.Core
|
|||||||
static void IncreaseCapacities(CapacityIncreaseMode increaseMode)
|
static void IncreaseCapacities(CapacityIncreaseMode increaseMode)
|
||||||
{
|
{
|
||||||
int killAdd = 0;
|
int killAdd = 0;
|
||||||
|
// int increaseTweenersBy = _DefaultMaxTweeners;
|
||||||
|
// int increaseSequencesBy = _DefaultMaxSequences;
|
||||||
|
int increaseTweenersBy = Mathf.Max((int)(maxTweeners * 1.5f), _DefaultMaxTweeners);
|
||||||
|
int increaseSequencesBy = Mathf.Max((int)(maxSequences * 1.5f), _DefaultMaxSequences);
|
||||||
switch (increaseMode) {
|
switch (increaseMode) {
|
||||||
case CapacityIncreaseMode.TweenersOnly:
|
case CapacityIncreaseMode.TweenersOnly:
|
||||||
killAdd += _DefaultMaxTweeners;
|
killAdd += increaseTweenersBy;
|
||||||
maxTweeners += _DefaultMaxTweeners;
|
maxTweeners += increaseTweenersBy;
|
||||||
Array.Resize(ref _pooledTweeners, maxTweeners);
|
Array.Resize(ref _pooledTweeners, maxTweeners);
|
||||||
break;
|
break;
|
||||||
case CapacityIncreaseMode.SequencesOnly:
|
case CapacityIncreaseMode.SequencesOnly:
|
||||||
killAdd += _DefaultMaxSequences;
|
killAdd += increaseSequencesBy;
|
||||||
maxSequences += _DefaultMaxSequences;
|
maxSequences += increaseSequencesBy;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
killAdd += _DefaultMaxTweeners;
|
killAdd += increaseTweenersBy;
|
||||||
maxTweeners += _DefaultMaxTweeners;
|
maxTweeners += increaseTweenersBy;
|
||||||
maxSequences += _DefaultMaxSequences;
|
maxSequences += increaseSequencesBy;
|
||||||
Array.Resize(ref _pooledTweeners, maxTweeners);
|
Array.Resize(ref _pooledTweeners, maxTweeners);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,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.0.330";
|
public static readonly string Version = "1.0.335";
|
||||||
|
|
||||||
///////////////////////////////////////////////
|
///////////////////////////////////////////////
|
||||||
// Options ////////////////////////////////////
|
// Options ////////////////////////////////////
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user