1
0
mirror of https://github.com/Cardidi/dotween-upm-fork.git synced 2025-12-20 17:26:03 +08:00

Fixed rare but randomly happening IndexOutOfRange exception (finally, wohoo!)

This commit is contained in:
Daniele Giardini 2015-03-23 18:11:22 +01:00
parent 2d562c4829
commit a7458f0445
15 changed files with 108 additions and 19 deletions

View 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));
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e8e1d53ce928f164c802c0d586a0ab9f
timeCreated: 1427113863
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 994c5705c1d317845a93116b134051cd
timeCreated: 1427113851
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -15,7 +15,7 @@ namespace DG.Tweening.Core
{
const int _DefaultMaxTweeners = 200;
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 maxTweeners = _DefaultMaxTweeners; // Always >= maxSequences
@ -81,12 +81,14 @@ namespace DG.Tweening.Core
}
} else {
// Increase capacity in case max number of Tweeners has already been reached, then continue
if (totTweeners >= maxTweeners) {
if (Debugger.logPriority >= 1) Debugger.LogWarning(_MaxTweensReached
.Replace("#0", maxTweeners + "/" + maxSequences)
.Replace("#1", (maxTweeners + _DefaultMaxTweeners) + "/" + maxSequences)
);
if (totTweeners >= maxTweeners - 1) {
int prevMaxTweeners = maxTweeners;
int prevMaxSequences = maxSequences;
IncreaseCapacities(CapacityIncreaseMode.TweenersOnly);
if (Debugger.logPriority >= 1) Debugger.LogWarning(_MaxTweensReached
.Replace("#0", prevMaxTweeners + "/" + prevMaxSequences)
.Replace("#1", maxTweeners + "/" + maxSequences)
);
}
}
// Not found: create new TweenerController
@ -108,12 +110,14 @@ namespace DG.Tweening.Core
return s;
}
// Increase capacity in case max number of Sequences has already been reached, then continue
if (totSequences >= maxSequences) {
if (Debugger.logPriority >= 1) Debugger.LogWarning(_MaxTweensReached
.Replace("#0", maxTweeners + "/" + maxSequences)
.Replace("#1", maxTweeners + "/" + (maxSequences + _DefaultMaxSequences))
);
if (totSequences >= maxSequences - 1) {
int prevMaxTweeners = maxTweeners;
int prevMaxSequences = maxSequences;
IncreaseCapacities(CapacityIncreaseMode.SequencesOnly);
if (Debugger.logPriority >= 1) Debugger.LogWarning(_MaxTweensReached
.Replace("#0", prevMaxTweeners + "/" + prevMaxSequences)
.Replace("#1", maxTweeners + "/" + maxSequences)
);
}
// Not found: create new Sequence
s = new Sequence();
@ -802,20 +806,24 @@ namespace DG.Tweening.Core
static void IncreaseCapacities(CapacityIncreaseMode increaseMode)
{
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) {
case CapacityIncreaseMode.TweenersOnly:
killAdd += _DefaultMaxTweeners;
maxTweeners += _DefaultMaxTweeners;
killAdd += increaseTweenersBy;
maxTweeners += increaseTweenersBy;
Array.Resize(ref _pooledTweeners, maxTweeners);
break;
case CapacityIncreaseMode.SequencesOnly:
killAdd += _DefaultMaxSequences;
maxSequences += _DefaultMaxSequences;
killAdd += increaseSequencesBy;
maxSequences += increaseSequencesBy;
break;
default:
killAdd += _DefaultMaxTweeners;
maxTweeners += _DefaultMaxTweeners;
maxSequences += _DefaultMaxSequences;
killAdd += increaseTweenersBy;
maxTweeners += increaseTweenersBy;
maxSequences += increaseSequencesBy;
Array.Resize(ref _pooledTweeners, maxTweeners);
break;
}

View File

@ -21,7 +21,7 @@ namespace DG.Tweening
public class DOTween
{
/// <summary>DOTween's version</summary>
public static readonly string Version = "1.0.330";
public static readonly string Version = "1.0.335";
///////////////////////////////////////////////
// Options ////////////////////////////////////

Binary file not shown.