Loop inside embed loop+race structure never gets cancelled

Summary

Here’s the repro

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }

test_device := class(creative_device):

    OnBegin<override>()<suspends> : void =
        loop: # Fake loop, will only iterate once
            Print("START RACE")

            race:
                Sleep(1.0)
                loop:
                    race:
                        Sleep(Inf)
                        loop:
                            Sleep(0.4)
                            Print("LOOPING") # Never stops printing

            Print("END RACE") # Prints after 1s
            Sleep(Inf)

Will print

[2024.10.28-12.16.18:084][709]LogVerse: : START RACE
[2024.10.28-12.16.18:485][756]LogVerse: : LOOPING
[2024.10.28-12.16.18:885][804]LogVerse: : LOOPING
[2024.10.28-12.16.19:085][828]LogVerse: : END RACE
[2024.10.28-12.16.19:285][852]LogVerse: : LOOPING
[2024.10.28-12.16.19:695][901]LogVerse: : LOOPING
[2024.10.28-12.16.20:097][949]LogVerse: : LOOPING
[2024.10.28-12.16.20:498][997]LogVerse: : LOOPING
[2024.10.28-12.16.20:898][ 45]LogVerse: : LOOPING
[2024.10.28-12.16.21:298][ 93]LogVerse: : LOOPING
... # Infinite looping

Please select what you are reporting on:

Verse

What Type of Bug are you experiencing?

Verse

Steps to Reproduce

See repro

Expected Result

See repro

Observed Result

See repro

Platform(s)

PC

Found by @Dr.Joske (Race is finished but one can still trigger event inside of it)

Apparently, this is the fix (move the whole race inside a method, I didn’t know races where aware of their suspending method, I thought they would be aware of their suspending scope only)

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }

test_device := class(creative_device):

    OnBegin<override>()<suspends> : void =
        loop: # Fake loop, will only iterate once
            Print("START RACE")

            race:
                Sleep(1.0)
                loop:
                    LoopPrint()

            Print("END RACE") # Prints after 1s
            Sleep(Inf)
        
    LoopPrint()<suspends>:void=
        race:
            Sleep(Inf)
            loop:
                Sleep(0.4)
                Print("LOOPING")
1 Like