-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from AnnulusGames/fix-possibility-of-double-r…
…elease Fix: possibility of double release
- Loading branch information
Showing
5 changed files
with
63 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/LitMotion/Assets/LitMotion/Runtime/Internal/RewindableAllocatorFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
using Unity.Collections; | ||
|
||
#if UNITY_EDITOR | ||
using UnityEditor; | ||
#endif | ||
|
||
namespace LitMotion | ||
{ | ||
internal static class RewindableAllocatorFactory | ||
{ | ||
const int InitialSize = 128 * 1024; | ||
static bool isInitialized; | ||
static readonly Stack<AllocatorHelper<RewindableAllocator>> allocators = new(); | ||
|
||
public static AllocatorHelper<RewindableAllocator> CreateAllocator() | ||
{ | ||
Initialize(); | ||
|
||
var allocatorHelper = new AllocatorHelper<RewindableAllocator>(Allocator.Persistent); | ||
allocatorHelper.Allocator.Initialize(InitialSize, true); | ||
allocators.Push(allocatorHelper); | ||
|
||
return allocatorHelper; | ||
} | ||
|
||
static void Initialize() | ||
{ | ||
if (!isInitialized) | ||
{ | ||
#if UNITY_EDITOR | ||
AssemblyReloadEvents.beforeAssemblyReload += Dispose; | ||
#else | ||
UnityEngine.Application.quitting += Dispose; | ||
#endif | ||
isInitialized = true; | ||
} | ||
} | ||
|
||
static void Dispose() | ||
{ | ||
while (allocators.TryPop(out var allocatorHelper)) | ||
{ | ||
allocatorHelper.Allocator.Dispose(); | ||
allocatorHelper.Dispose(); | ||
} | ||
} | ||
} | ||
} |
File renamed without changes.
56 changes: 0 additions & 56 deletions
56
src/LitMotion/Assets/LitMotion/Runtime/Internal/SharedRewindableAllocator.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters