Infinite loop errors in map - best troubleshooting practices?

Hello,

so I just see technical errors with infinite loop glitch, what is the best troubleshooting method for finding the source?

I have custom dragon movement devices in the game + raycasting for movement, I assume one of these would be the cause, but I have no idea how to pinpoint that, any ideas?

Error:

Map code:

2601-9029-8468

do you have Sleep in that update loop?

Not in this one afaik, its movement based script, so it would probably cause lags.

Can you show your MoveTo loop ? I’m thinking you’re setting a negative duration inside the MoveTo somehow

@im_a_lama
@laggyluk

You’re not expecting me to read this ? :smiley:

Thought it might be easier to just paste whole code to seach and in case of follow up questions.

This is the move loop:

 MoveTheDragon(FC:fort_character)<suspends>:void =
        MoveLimitSq := 2048.0 * 2048.0
        loop:
            Print("Dragon movement L00P")
            Sleep(0.1)
            if(IsActive?):
                SaddlePos := TamableDragon.GetTransform().Translation
                PlayerRot := FC.GetViewRotation()
                var MoveVector : vector3 = vector3{X:=0.0, Y:=0.0, Z:=0.0}
                
                # Calculate forward, right, and up vectors from the player's rotation
                # Calculate forward and right vectors from the player's rotation
                ForwardVector := PlayerRot.GetLocalForward()
                RightVector := vector3{
                    X := ForwardVector.Y,
                    Y := -ForwardVector.X,
                    Z := 0.0
                }

                # Up vector, which points upwards in the Z direction
                UpVector := vector3{
                    X := 0.0,
                    Y := 0.0,
                    Z := 1.0
                } 

                # Down vector, which points downwards in the Z direction
                DownVector := vector3{
                    X := 0.0,
                    Y := 0.0,
                    Z := -1.0
                } 
    
                if(MovingForward?):
                    PitchedRotation := PlayerRot.ApplyPitch(32.0)
                    set MoveVector = PitchedRotation.GetLocalForward() * 512.0
                
                if(MovingBack?):
                    set MoveVector = MoveVector + ForwardVector * -256.0
                
                if(MovingLeft?):
                    set MoveVector = MoveVector + RightVector * 384.0
                
                if(MovingRight?):
                    set MoveVector = MoveVector + RightVector * -384.0

                if(MovingUp?):
                    set MoveVector = MoveVector + UpVector * 384.0
    
                if(MovingDown?):
                    set MoveVector = MoveVector + UpVector * -384.0
        
    
                var MovePos : vector3 = SaddlePos + MoveVector
    
                var PathClear: logic = true
                if(A := MaybeOwnerAgent?):
                    DragonForwardPos := SaddlePos - vector3{X:=0.0, Y:=0.0, Z:=500.0}
                    MaybeHitLoc := MorituriRaycastDevice.RayCastForAgent(A, transform{Translation:=DragonForwardPos, Rotation:=PlayerRot, Scale:=vector3{X:=1.0, Y:=1.0, Z:=1.0}})
                    if(HitLoc := MaybeHitLoc?):
                        set MaybeFireballHitsPosition = option{HitLoc}
                        DistSq := DistanceSquared(HitLoc, SaddlePos)
                        if(DistSq < MoveLimitSq): 
                            set PathClear = false
                    else:
                        set MaybeFireballHitsPosition = false
    
                if(PathClear?):
                    spawn{TamableDragon.MoveTo(MovePos, PlayerRot, Speed)}
    
                if(A := MaybeOwnerAgent?):
                    FireballStartT := FirebreathRoot_Prop.GetTransform()
                    FireballForward := FireballStartT.Rotation.GetLocalForward()
                    FireballStart := FireballStartT.Translation + FireballForward * 500.0 + vector3{X:=0.0, Y:=0.0, Z:=200.0}
                    set MaybeFireballHitsPosition = MorituriRaycastDevice.RayCastForAgent(A, transform{Translation:=FireballStart, Rotation:=FireballStartT.Rotation, Scale:=vector3{X:=1.0, Y:=1.0, Z:=1.0}})
                
                if(P := MaybeFirebreathVFX?):
                    var T : transform = FirebreathDamageZone.GetTransform()
                    spawn{P.MoveTo(T, Speed)}
    
            else if(not IsActive?):
                break

And this is the moveto / follow loop on pets:

pet_data := class<concrete>:
    var CurrentProp : ?creative_prop = false
    #var MaybeParent: ?custom_pet_device = false

    StopSignal : event() = event(){}


    #Init(Parent: custom_pet_device):void=
       # set MaybeParent = option{Parent}

    RunFollow(FortCharacter : fort_character, PropAsset : creative_prop_asset, Offset : vector3)<suspends>:void = 
        SpawnedProp := SpawnProp(PropAsset, FortCharacter.GetTransform())
        PropInstance := SpawnedProp(0)
        if ( Prop := PropInstance?, not CurrentProp?):
            set CurrentProp = option{Prop}

            race:
                RunFollowInternal(FortCharacter, PropAsset, Offset)
                StopSignal.Await()

    RunFollowInternal(FortCharacter : fort_character, PropAsset : creative_prop_asset, Offset : vector3)<suspends> : void =
        if ( Prop := CurrentProp?):
            loop:
                Transform := FortCharacter.GetTransform()
                Rotation := Transform.Rotation
                OffsetVector := Rotation.RotateVector(Offset)

                GoalTranslation := Transform.Translation + OffsetVector
                GoalRotation := Transform.Rotation
                RotatedGoalRotation := GoalRotation

                Direction := (GoalTranslation - Prop.GetTransform().Translation)*10.0
                ForwardVelocityPoint := Direction +  Prop.GetTransform().Translation

                #if(Parent := MaybeParent?):
                    race:
                        Prop.MoveTo(ForwardVelocityPoint, GoalRotation, 3.0) #original was 3.0, and 0.3
                        Sleep(0.5)
            
    StopFollow() : void =
        StopSignal.Signal()
        if(Prop := CurrentProp?):
            Prop.Dispose()
        set CurrentProp = false

I think it’s the pet one, maybe the MoveTo call gets canceled immediately if the target location is the same as the previous location for example, try to add a Sleep(0.0) atleast in your loop

I think this sleep part does that no?

 #if(Parent := MaybeParent?):
                    race:
                        Prop.MoveTo(ForwardVelocityPoint, GoalRotation, 3.0) #original was 3.0, and 0.3
                        Sleep(0.5)

No, if MoveTo resolves instantly, then the Sleep() is canceled, that’s the purpose of race blocks

and then when your prop is already at target position there’s no sleep for the parent loop

1 Like

Btw. Wouldn’t the “overtime” parameter as the 3rd argument of the MoveTo function force the MoveTo to atleast stall the thread execution for that amount of time?

1 Like

I don’t think so, MoveTo can fail and get canceled as well, you just need to change your code

Do you think this should fix that?

pet_data := class<concrete>:
    var CurrentProp : ?creative_prop = false
    #var MaybeParent: ?custom_pet_device = false

    StopSignal : event() = event(){}


    #Init(Parent: custom_pet_device):void=
       # set MaybeParent = option{Parent}

    RunFollow(FortCharacter : fort_character, PropAsset : creative_prop_asset, Offset : vector3, MoveToTime : float , MoveInterruptTime : float)<suspends>:void = 
        SpawnedProp := SpawnProp(PropAsset, FortCharacter.GetTransform())
        PropInstance := SpawnedProp(0)
        if ( Prop := PropInstance?, not CurrentProp?):
            set CurrentProp = option{Prop}

            race:
                RunFollowInternal(FortCharacter, PropAsset, Offset, MoveToTime, MoveInterruptTime)
                StopSignal.Await()

    RunFollowInternal(FortCharacter : fort_character, PropAsset : creative_prop_asset, Offset : vector3, MoveToTime : float , MoveInterruptTime : float)<suspends> : void =
        if ( Prop := CurrentProp?):
            sync:
                Print("PET STARTED FOLLOWING PLAYER")
                loop:
                    Transform := FortCharacter.GetTransform()
                    Rotation := Transform.Rotation
                    OffsetVector := Rotation.RotateVector(Offset)

                    GoalTranslation := Transform.Translation + OffsetVector
                    GoalRotation := Transform.Rotation
                    RotatedGoalRotation := GoalRotation

                    Direction := (GoalTranslation - Prop.GetTransform().Translation)*10.0
                    ForwardVelocityPoint := Direction +  Prop.GetTransform().Translation

                    #if(Parent := MaybeParent?):
                    Sleep(0.01)
                    Print("Attempting to move pet to location: {ForwardVelocityPoint} with rotation: {GoalRotation}")
                        race:
                            Prop.MoveTo(ForwardVelocityPoint, GoalRotation, MoveToTime) #original was 3.0, and 0.3
                            Sleep(MoveInterruptTime)
                            
                StopSignal.Await()

            
    StopFollow() : void =
        StopSignal.Signal()
        Print("Stop signal received")
        if(Prop := CurrentProp?):
            Prop.Dispose()
            Print("Pet prop disposed")
        set CurrentProp = false

Hopefully fixed even tho I would need more discovery time to know for sure.

1 Like