FlaxEngine / FlaxEngine/FlaxEngine
Scripting.RunOnUpdate leaks between play modes?
- Dominant language
- C++
- Stars
- 7k
- Forks
- 713
- Avg merge
- 7d 11h
- Merged PRs (30d)
- 19
Description
Not sure what's happening in here.
I have this utility to delay, synced with update loop:
```csharp
public static async Task Delay(float time, CancellationToken? cancellationToken = null) {
float passedTime = 0;
Action action = () => passedTime += Time.DeltaTime;
while (passedTime < time) {
if (cancellationToken is CancellationToken validToken && validToken.IsCancellationRequested) throw new TaskCanceledException();
await Scripting.RunOnUpdate(action);
}
}
```
If I:
1. Attach this script to an actor:
```csharp
public class Test : Script
{
public override async void OnAwake() {
Engine.RequestExit();
await FlaxyTasks.Delay(1); // I'm aware that I should cancel it on OnDestroy
Debug.Log("I shouldn't log!");
}
}
```
2. Run play mode once
3. Detach script (there's no such script in the scene at all)
4. Run play mode again
5. After a ~second "I shouldn't log!" appears in the Debug Log
I'm not sure this is intended behavior.
Tested on master branch.
Contributor guide
Assessment
This issue has not been assessed yet.