landelare / ue5coro

A C++20 coroutine implementation for Unreal Engine 5 that feels almost native.
BSD 3-Clause Clear License
543 stars 48 forks source link

Coroutine crash when opening or leaving level in editor (game not running) #23

Closed nwilson100 closed 6 months ago

nwilson100 commented 6 months ago

I encountered this crash while attempting to create a clean repro for a different crash I was encountering. I'm unsure if anyone would realistically encounter this specific situation, but in case it might help improve the systems, figured I would also report this.

This was tested including the recent changes in your commit 0cf2485.

Source for required class CoroExitTest attached to this issue: CoroEditorLevelCrash.zip

Repro Case A:

  1. Make empty level I'll refer to as "TestLevel".
  2. Ensure the game mode is set to the blank GameModeBase.
  3. Place an actor of type CoroExitTest in TestLevel.
  4. Open another level in editor.
  5. The editor will crash at this point.

Repro Case B:

  1. Reuse the TestLevel from repro case A.
  2. Start the editor.
  3. Open TestLevel.
  4. The editor will crash at this point.

Images here for the call stack of the crash and information about the FLatentPromise. The coro frame ptr is not available at the point of crashing, so no image of its state is provided. CrashPoint1 LatentPromise1

landelare commented 6 months ago

ACoroExitTest::BeginDestroy() is calling the coroutine when Case A: !IsValid(this) Case B: !IsValid(GetWorld()) Guarding against both resolves the crash in the repro case.

The issue of FLatentPromise being too generous with starting latent actions is exactly the same as in #22 so I'll close this one as a duplicate.