【发布时间】:2022-01-31 07:10:27
【问题描述】:
谷歌搜索后,我认为这是内存泄漏,但我不知道如何解决这个问题。
断言失败:TLS 分配器 ALLOC_TEMP_THREAD,底层分配器 ALLOC_TEMP_THREAD 有未释放的分配,大小 1528
我正在使用 Unity 2018.1.0.0f2。
这是导致错误的脚本(对不起,我糟糕的代码组织技能,新世界一代)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WorldGeneration : MonoBehaviour {
public float GenerationDelay;
public float RoomPicker;
public float LevelNumber;
public float RoomCount;
public float MaxRoomCount;
public float LevelSample1Rooms;
public float MaxLevelSample1Rooms;
public float LevelSample2Rooms;
public float MaxLevelSample2Rooms;
public float LevelSample3Rooms;
public float MaxLevelSample3Rooms;
public float LevelSample4Rooms;
public float MaxLevelSample4Rooms;
public float LevelSample5Rooms;
public float MaxLevelSample5Rooms;
public GameObject LevelSample1;
public GameObject LevelSample2;
public GameObject LevelSample3;
public GameObject LevelSample4;
public GameObject LevelSample5;
public Transform SpawnLevelPoint;
public Transform SpawnLevelPoint1;
public bool Leveloadedatpoint1;
public Transform SpawnLevelPoint2;
public bool Leveloadedatpoint2;
public Transform SpawnLevelPoint3;
public bool Leveloadedatpoint3;
public Transform SpawnLevelPoint4;
public bool Leveloadedatpoint4;
public Transform SpawnLevelPoint5;
public bool Leveloadedatpoint5;
public Transform SpawnLevelPoint6;
public bool Leveloadedatpoint6;
void Start()
{
StartCoroutine("Createpoint1room");
}
public IEnumerator Createpoint1room()
{
if (Leveloadedatpoint1 == false)
{
RoomPicker = Random.Range(1, 20);
yield return new WaitForSeconds(GenerationDelay);
if (RoomPicker == 1 || RoomPicker == 2 || RoomPicker == 3 || RoomPicker == 4 || RoomPicker == 5)
{
if (Leveloadedatpoint1 == false)
{
if (LevelSample1Rooms < MaxLevelSample1Rooms)
{
LevelSample1Rooms += 1;
Instantiate(LevelSample1, SpawnLevelPoint1.transform.position, Quaternion.identity);
Leveloadedatpoint1 = true;
yield return new WaitForSeconds(GenerationDelay);
StartCoroutine("Createpoint2room");
}
else
{
StartCoroutine("Createpoint1room");
}
}
else
{
StartCoroutine("Createpoint1room");
}
}
if (RoomPicker == 6 || RoomPicker == 7 || RoomPicker == 8)
{
if (Leveloadedatpoint1 == false)
{
if (LevelSample2Rooms < MaxLevelSample2Rooms)
{
LevelSample2Rooms += 1;
Instantiate(LevelSample2, SpawnLevelPoint1.transform.position, Quaternion.identity);
Leveloadedatpoint1 = true;
yield return new WaitForSeconds(GenerationDelay);
StartCoroutine("Createpoint2room");
}
else
{
StartCoroutine("Createpoint1room");
}
}
else
{
StartCoroutine("Createpoint1room");
}
}
if (RoomPicker == 9 || RoomPicker == 10 || RoomPicker == 11)
{
if (Leveloadedatpoint1 == false)
{
if (LevelSample3Rooms < MaxLevelSample3Rooms)
{
LevelSample3Rooms += 1;
Instantiate(LevelSample3, SpawnLevelPoint1.transform.position, Quaternion.identity);
Leveloadedatpoint1 = true;
yield return new WaitForSeconds(GenerationDelay);
StartCoroutine("Createpoint2room");
}
else
{
StartCoroutine("Createpoint1room");
}
}
else
{
StartCoroutine("Createpoint1room");
}
}
if (RoomPicker == 12 || RoomPicker == 13 || RoomPicker == 14)
{
if (Leveloadedatpoint1 == false)
{
if (LevelSample4Rooms < MaxLevelSample4Rooms)
{
LevelSample4Rooms += 1;
Instantiate(LevelSample4, SpawnLevelPoint1.transform.position, Quaternion.identity);
Leveloadedatpoint1 = true;
yield return new WaitForSeconds(GenerationDelay);
StartCoroutine("Createpoint2room");
}
else
{
StartCoroutine("Createpoint1room");
}
}
else
{
StartCoroutine("Createpoint1room");
}
}
if (RoomPicker == 15 || RoomPicker == 16 || RoomPicker == 17)
{
if (Leveloadedatpoint1 == false)
{
if (LevelSample5Rooms < MaxLevelSample5Rooms)
{
LevelSample5Rooms += 1;
Instantiate(LevelSample5, SpawnLevelPoint1.transform.position, Quaternion.identity);
Leveloadedatpoint1 = true;
yield return new WaitForSeconds(GenerationDelay);
StartCoroutine("Createpoint2room");
}
else
{
StartCoroutine("Createpoint1room");
}
}
else
{
StartCoroutine("Createpoint1room");
}
}
if (RoomPicker == 18 || RoomPicker == 19 || RoomPicker == 20)
{
StartCoroutine("Createpoint1room");
}
Debug.Log("Point 1: The number is " + RoomPicker);
}
else
{
StartCoroutine("Createpoint2room");
}
}
public IEnumerator Createpoint2room()
{
if (Leveloadedatpoint2 == false)
{
RoomPicker = Random.Range(1, 20);
yield return new WaitForSeconds(GenerationDelay);
if (RoomPicker == 1 || RoomPicker == 2 || RoomPicker == 3 || RoomPicker == 4 || RoomPicker == 5)
{
if (Leveloadedatpoint2 == false)
{
if (LevelSample1Rooms < MaxLevelSample1Rooms)
{
LevelSample1Rooms += 1;
Instantiate(LevelSample1, SpawnLevelPoint2.transform.position, Quaternion.identity);
Leveloadedatpoint2 = true;
yield return new WaitForSeconds(GenerationDelay);
StartCoroutine("Createpoint3room");
}
else
{
StartCoroutine("Createpoint2room");
}
}
else
{
StartCoroutine("Createpoint2room");
}
}
if (RoomPicker == 6 || RoomPicker == 7 || RoomPicker == 8)
{
if (Leveloadedatpoint2 == false)
{
if (LevelSample2Rooms < MaxLevelSample2Rooms)
{
LevelSample2Rooms += 1;
Instantiate(LevelSample2, SpawnLevelPoint2.transform.position, Quaternion.identity);
Leveloadedatpoint2 = true;
yield return new WaitForSeconds(GenerationDelay);
StartCoroutine("Createpoint3room");
}
else
{
StartCoroutine("Createpoint2room");
}
}
else
{
StartCoroutine("Createpoint2room");
}
}
if (RoomPicker == 9 || RoomPicker == 10 || RoomPicker == 11)
{
if (Leveloadedatpoint2 == false)
{
if (LevelSample3Rooms < MaxLevelSample3Rooms)
{
LevelSample3Rooms += 1;
Instantiate(LevelSample3, SpawnLevelPoint2.transform.position, Quaternion.identity);
Leveloadedatpoint2 = true;
yield return new WaitForSeconds(GenerationDelay);
StartCoroutine("Createpoint3room");
}
else
{
StartCoroutine("Createpoint2room");
}
}
else
{
StartCoroutine("Createpoint2room");
}
}
if (RoomPicker == 12 || RoomPicker == 13 || RoomPicker == 14)
{
if (Leveloadedatpoint2 == false)
{
if (LevelSample4Rooms < MaxLevelSample4Rooms)
{
LevelSample4Rooms += 1;
Instantiate(LevelSample4, SpawnLevelPoint2.transform.position, Quaternion.identity);
Leveloadedatpoint2 = true;
yield return new WaitForSeconds(GenerationDelay);
StartCoroutine("Createpoint3room");
}
else
{
StartCoroutine("Createpoint2room");
}
}
else
{
StartCoroutine("Createpoint2room");
}
}
if (RoomPicker == 15 || RoomPicker == 16 || RoomPicker == 17)
{
if (Leveloadedatpoint2 == false)
{
if (LevelSample5Rooms < MaxLevelSample5Rooms)
{
LevelSample5Rooms += 1;
Instantiate(LevelSample5, SpawnLevelPoint2.transform.position, Quaternion.identity);
Leveloadedatpoint2 = true;
yield return new WaitForSeconds(GenerationDelay);
StartCoroutine("Createpoint3room");
}
else
{
StartCoroutine("Createpoint2room");
}
}
else
{
StartCoroutine("Createpoint2room");
}
}
if (RoomPicker == 18 || RoomPicker == 19 || RoomPicker == 20)
{
StartCoroutine("Createpoint2room");
}
Debug.Log("Point 2: The number is " + RoomPicker);
}
else
{
StartCoroutine("Createpoint3room");
}
}
public IEnumerator Createpoint3room()
{
if (Leveloadedatpoint3 == false)
{
RoomPicker = Random.Range(1, 20);
yield return new WaitForSeconds(GenerationDelay);
if (RoomPicker == 1 || RoomPicker == 2 || RoomPicker == 3 || RoomPicker == 4 || RoomPicker == 5)
{
if (Leveloadedatpoint3 == false)
{
if (LevelSample1Rooms < MaxLevelSample1Rooms)
{
LevelSample1Rooms += 1;
Instantiate(LevelSample1, SpawnLevelPoint3.transform.position, Quaternion.identity);
Leveloadedatpoint3 = true;
yield return new WaitForSeconds(GenerationDelay);
StartCoroutine("Createpoint4room");
}
else
{
StartCoroutine("Createpoint3room");
}
}
else
{
StartCoroutine("Createpoint3room");
}
}
if (RoomPicker == 6 || RoomPicker == 7 || RoomPicker == 8)
{
if (Leveloadedatpoint3 == false)
{
if (LevelSample2Rooms < MaxLevelSample2Rooms)
{
LevelSample2Rooms += 1;
Instantiate(LevelSample2, SpawnLevelPoint3.transform.position, Quaternion.identity);
Leveloadedatpoint3 = true;
yield return new WaitForSeconds(GenerationDelay);
StartCoroutine("Createpoint4room");
}
else
{
StartCoroutine("Createpoint3room");
}
}
else
{
StartCoroutine("Createpoint3room");
}
}
if (RoomPicker == 9 || RoomPicker == 10 || RoomPicker == 11)
{
if (Leveloadedatpoint3 == false)
{
if (LevelSample3Rooms < MaxLevelSample3Rooms)
{
LevelSample3Rooms += 1;
Instantiate(LevelSample3, SpawnLevelPoint3.transform.position, Quaternion.identity);
Leveloadedatpoint3 = true;
yield return new WaitForSeconds(GenerationDelay);
StartCoroutine("Createpoint4room");
}
else
{
StartCoroutine("Createpoint3room");
}
}
else
{
StartCoroutine("Createpoint3room");
}
}
if (RoomPicker == 12 || RoomPicker == 13 || RoomPicker == 14)
{
if (Leveloadedatpoint3 == false)
{
if (LevelSample4Rooms < MaxLevelSample4Rooms)
{
LevelSample4Rooms += 1;
Instantiate(LevelSample4, SpawnLevelPoint3.transform.position, Quaternion.identity);
Leveloadedatpoint3 = true;
yield return new WaitForSeconds(GenerationDelay);
StartCoroutine("Createpoint4room");
}
else
{
StartCoroutine("Createpoint3room");
}
}
else
{
StartCoroutine("Createpoint3room");
}
}
if (RoomPicker == 15 || RoomPicker == 16 || RoomPicker == 17)
{
if (Leveloadedatpoint3 == false)
{
if (LevelSample5Rooms < MaxLevelSample5Rooms)
{
LevelSample5Rooms += 1;
Instantiate(LevelSample5, SpawnLevelPoint3.transform.position, Quaternion.identity);
Leveloadedatpoint3 = true;
yield return new WaitForSeconds(GenerationDelay);
StartCoroutine("Createpoint4room");
}
else
{
StartCoroutine("Createpoint3room");
}
}
else
{
StartCoroutine("Createpoint3room");
}
}
if (RoomPicker == 18 || RoomPicker == 19 || RoomPicker == 20)
{
StartCoroutine("Createpoint3room");
}
Debug.Log("Point 3: The number is " + RoomPicker);
}
else
{
StartCoroutine("Createpoint4room");
}
}
public IEnumerator Createpoint4room()
{
if (Leveloadedatpoint4 == false)
{
RoomPicker = Random.Range(1, 20);
yield return new WaitForSeconds(GenerationDelay);
if (RoomPicker == 1 || RoomPicker == 2 || RoomPicker == 3 || RoomPicker == 4 || RoomPicker == 5)
{
if (Leveloadedatpoint4 == false)
{
if (LevelSample1Rooms < MaxLevelSample1Rooms)
{
LevelSample1Rooms += 1;
Instantiate(LevelSample1, SpawnLevelPoint4.transform.position, Quaternion.identity);
Leveloadedatpoint4 = true;
yield return new WaitForSeconds(GenerationDelay);
StartCoroutine("Createpoint5room");
}
else
{
StartCoroutine("Createpoint4room");
}
}
else
{
StartCoroutine("Createpoint4room");
}
}
if (RoomPicker == 6 || RoomPicker == 7 || RoomPicker == 8)
{
if (Leveloadedatpoint4 == false)
{
if (LevelSample2Rooms < MaxLevelSample2Rooms)
{
LevelSample2Rooms += 1;
Instantiate(LevelSample2, SpawnLevelPoint4.transform.position, Quaternion.identity);
Leveloadedatpoint4 = true;
yield return new WaitForSeconds(GenerationDelay);
StartCoroutine("Createpoint5room");
}
else
{
StartCoroutine("Createpoint4room");
}
}
else
{
StartCoroutine("Createpoint4room");
}
}
if (RoomPicker == 9 || RoomPicker == 10 || RoomPicker == 11)
{
if (Leveloadedatpoint4 == false)
{
if (LevelSample3Rooms < MaxLevelSample3Rooms)
{
LevelSample3Rooms += 1;
Instantiate(LevelSample3, SpawnLevelPoint4.transform.position, Quaternion.identity);
Leveloadedatpoint4 = true;
yield return new WaitForSeconds(GenerationDelay);
StartCoroutine("Createpoint5room");
}
else
{
StartCoroutine("Createpoint4room");
}
}
else
{
StartCoroutine("Createpoint4room");
}
}
if (RoomPicker == 12 || RoomPicker == 13 || RoomPicker == 14)
{
if (Leveloadedatpoint4 == false)
{
if (LevelSample4Rooms < MaxLevelSample4Rooms)
{
LevelSample4Rooms += 1;
Instantiate(LevelSample4, SpawnLevelPoint4.transform.position, Quaternion.identity);
Leveloadedatpoint3 = true;
yield return new WaitForSeconds(GenerationDelay);
StartCoroutine("Createpoint4room");
}
else
{
StartCoroutine("Createpoint4room");
}
}
else
{
StartCoroutine("Createpoint4room");
}
}
if (RoomPicker == 15 || RoomPicker == 16 || RoomPicker == 17)
{
if (Leveloadedatpoint3 == false)
{
if (LevelSample5Rooms < MaxLevelSample5Rooms)
{
LevelSample5Rooms += 1;
Instantiate(LevelSample5, SpawnLevelPoint4.transform.position, Quaternion.identity);
Leveloadedatpoint3 = true;
yield return new WaitForSeconds(GenerationDelay);
StartCoroutine("Createpoint5room");
}
else
{
StartCoroutine("Createpoint4room");
}
}
else
{
StartCoroutine("Createpoint4room");
}
}
if (RoomPicker == 18 || RoomPicker == 19 || RoomPicker == 20)
{
StartCoroutine("Createpoint4room");
}
Debug.Log("Point 4: The number is " + RoomPicker);
}
else
{
StartCoroutine("Createpoint4room");
}
}
public IEnumerator Createpoint5room()
{
yield return new WaitForSeconds(GenerationDelay);
Debug.Log("Generation finished");
}
}
编辑1: 这个错误似乎也让我的编辑器崩溃了,游戏的构建也崩溃了。
【问题讨论】:
-
我也有同样的问题,我认为是因为协程。
-
有问题的人想法一致?
-
刚刚添加了正确的答案,现在看下面,稍后再告诉我!-)