浏览代码

Fix Native array leak

/main
Andre McGrail 4 年前
当前提交
8cfd749a
共有 4 个文件被更改,包括 30 次插入16 次删除
  1. 19
      Packages/com.verasl.water-system/Scripts/BuoyantObject.cs
  2. 6
      Packages/com.verasl.water-system/Scripts/GerstnerWavesJobs.cs
  3. 12
      Packages/com.verasl.water-system/Scripts/LocalToWorldJob.cs
  4. 9
      Packages/com.verasl.water-system/Scripts/Water.cs

19
Packages/com.verasl.water-system/Scripts/BuoyantObject.cs


}
private void LateUpdate() { LocalToWorldConversion(); }
private void OnDestroy()
{
CleanUp();
}
private void OnDisable() { LocalToWorldJob.Cleanup(_guid); }
private void OnDestroy() { LocalToWorldJob.Cleanup(_guid); }
void CleanUp()
{
if (_buoyancyType == BuoyancyType.Physical || _buoyancyType == BuoyancyType.PhysicalVoxel)
{
LocalToWorldJob.Cleanup(_guid);
}
else
{
_samplePoints.Dispose();
}
}
private void LocalToWorldConversion()
{

6
Packages/com.verasl.water-system/Scripts/GerstnerWavesJobs.cs


public static void Init()
{
Debug.Log("Initializing Gerstner Waves Jobs");
//Wave data
_waveCount = Water.Instance._waves.Length;
_waveData = new NativeArray<Wave>(_waveCount, Allocator.Persistent);

public static void Cleanup()
{
Debug.Log("Cleaning up Gerstner Wave Jobs");
_positions.Dispose();
_wavePos.Dispose();
_waveNormal.Dispose();

if (_positionCount + samplePoints.Length >= _positions.Length) return;
offsets = new int2(_positionCount, _positionCount + samplePoints.Length);
//Debug.Log("<color=yellow>Adding Object:" + guid + " to the registry at offset:" + offsets + "</color>");
Registry.Add(guid, offsets);
_positionCount += samplePoints.Length;
}

_processing = true;
// Buoyant Object Job
var waterHeight = new GerstnerWavesJobs.HeightJob()
var waterHeight = new HeightJob()
{
WaveData = _waveData,
Position = _positions,

12
Packages/com.verasl.water-system/Scripts/LocalToWorldJob.cs


public static void Cleanup(int guid)
{
if (Data.ContainsKey(guid))
{
Data[guid].Handle.Complete();
Data[guid].PositionsWorld.Dispose();
Data[guid].PositionsLocal.Dispose();
Data.Remove(guid);
}
if (!Data.ContainsKey(guid)) return;
Data[guid].Handle.Complete();
Data[guid].PositionsWorld.Dispose();
Data[guid].PositionsLocal.Dispose();
Data.Remove(guid);
}
class TransformLocalToWorld

9
Packages/com.verasl.water-system/Scripts/Water.cs


}
}
private void OnDisable() {
private void OnDestroy() {
private void OnApplicationQuit()
{
GerstnerWavesJobs.Cleanup();
}
//if(Application.isPlaying)
//GerstnerWavesJobs.Cleanup();
RenderPipelineManager.beginCameraRendering -= BeginCameraRendering;
if (_depthCam)
{

正在加载...
取消
保存