Skip to content

Commit

Permalink
Fix omissions in Addressable.Release and IsValid checks
Browse files Browse the repository at this point in the history
  • Loading branch information
hadashiA committed Jan 25, 2024
1 parent 36ac086 commit ee12dd9
Showing 1 changed file with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static AsyncOperationHandleConfiguredSource()
TaskPool.RegisterSizeGetter(typeof(AsyncOperationHandleConfiguredSource), () => pool.Size);
}

readonly Action<AsyncOperationHandle> continuationAction;
readonly Action<AsyncOperationHandle> completedCallback;
AsyncOperationHandle handle;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
Expand All @@ -120,7 +120,7 @@ static AsyncOperationHandleConfiguredSource()

AsyncOperationHandleConfiguredSource()
{
continuationAction = Continuation;
completedCallback = HandleCompleted;
}

public static IUniTaskSource Create(AsyncOperationHandle handle, PlayerLoopTiming timing, IProgress<float> progress, CancellationToken cancellationToken, bool cancelImmediately, out short token)
Expand All @@ -145,6 +145,10 @@ public static IUniTaskSource Create(AsyncOperationHandle handle, PlayerLoopTimin
result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state =>
{
var promise = (AsyncOperationHandleConfiguredSource)state;
if (promise.handle.IsValid())
{
Addressables.Release(promise.handle);
}
promise.core.TrySetCanceled(promise.cancellationToken);
}, result);
}
Expand All @@ -153,15 +157,18 @@ public static IUniTaskSource Create(AsyncOperationHandle handle, PlayerLoopTimin

PlayerLoopHelper.AddAction(timing, result);

handle.Completed += result.continuationAction;
handle.Completed += result.completedCallback;

token = result.core.Version;
return result;
}

void Continuation(AsyncOperationHandle _)
void HandleCompleted(AsyncOperationHandle _)
{
handle.Completed -= continuationAction;
if (handle.IsValid())
{
handle.Completed -= completedCallback;
}

if (completed)
{
Expand All @@ -172,7 +179,7 @@ void Continuation(AsyncOperationHandle _)
completed = true;
if (cancellationToken.IsCancellationRequested)
{
If (handle.IsValid())
if (handle.IsValid())
{
Addressables.Release(handle);
}
Expand Down Expand Up @@ -299,7 +306,7 @@ static AsyncOperationHandleConfiguredSource()
TaskPool.RegisterSizeGetter(typeof(AsyncOperationHandleConfiguredSource<T>), () => pool.Size);
}

readonly Action<AsyncOperationHandle<T>> continuationAction;
readonly Action<AsyncOperationHandle<T>> completedCallback;
AsyncOperationHandle<T> handle;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
Expand All @@ -310,7 +317,7 @@ static AsyncOperationHandleConfiguredSource()

AsyncOperationHandleConfiguredSource()
{
continuationAction = Continuation;
completedCallback = HandleCompleted;
}

public static IUniTaskSource<T> Create(AsyncOperationHandle<T> handle, PlayerLoopTiming timing, IProgress<float> progress, CancellationToken cancellationToken, bool cancelImmediately, out short token)
Expand All @@ -335,6 +342,10 @@ public static IUniTaskSource<T> Create(AsyncOperationHandle<T> handle, PlayerLoo
result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state =>
{
var promise = (AsyncOperationHandleConfiguredSource<T>)state;
if (promise.handle.IsValid())
{
Addressables.Release(promise.handle);
}
promise.core.TrySetCanceled(promise.cancellationToken);
}, result);
}
Expand All @@ -343,15 +354,18 @@ public static IUniTaskSource<T> Create(AsyncOperationHandle<T> handle, PlayerLoo

PlayerLoopHelper.AddAction(timing, result);

handle.Completed += result.continuationAction;
handle.Completed += result.completedCallback;

token = result.core.Version;
return result;
}

void Continuation(AsyncOperationHandle<T> argHandle)
void HandleCompleted(AsyncOperationHandle<T> argHandle)
{
handle.Completed -= continuationAction;
if (handle.IsValid())
{
handle.Completed -= completedCallback;
}

if (completed)
{
Expand Down

0 comments on commit ee12dd9

Please sign in to comment.