Problems with leaks

Level 4
Joined
Sep 9, 2010
Messages
72
I have a problem with a triggered spell, when I use the spell for about 5-6 times it creates lag. I think the problem is the leaks but I'm not good at clearing Leaks even though I read all the tutorials I found.

Triggers:

  • Start Ray
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Ray
    • Actions
      • Wait 0.10 seconds
      • Unit - Order (Casting unit) to Hold Position
      • Animation - Play (Casting unit)'s attack animation
      • Player - Disable Ray for (Owner of (Casting unit))
      • Unit - Add Cancel to (Casting unit)
      • Player Group - Add (Owner of (Casting unit)) to Ray_Casters
      • Set Ray_Damage[(Player number of (Owner of (Casting unit)))] = 0.00
      • Set Ray_Distance[(Player number of (Owner of (Casting unit)))] = 0.00
      • Set Ray_Caster[(Player number of (Owner of (Casting unit)))] = (Casting unit)
      • Set Ray_Angle[(Player number of (Owner of (Casting unit)))] = (Facing of (Casting unit))
      • Set Ray_Point[(Player number of (Owner of (Casting unit)))] = ((Position of (Casting unit)) offset by 50.00 towards Ray_Angle[(Player number of (Owner of (Casting unit)))] degrees)
      • Set Ray_Timer[(Player number of (Owner of (Casting unit)))] = 0.00
      • Trigger - Turn on Channel Ray <gen>

  • Channel Ray
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Player Group - Pick every player in Ray_Casters and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Ray_Timer[(Player number of (Picked player))] Greater than or equal to 1.95
            • Then - Actions
              • Set Ray_Timer[(Player number of (Owner of (Casting unit)))] = 0.00
              • Player - Enable Ray for (Picked player)
              • Unit - Remove Cancel from Ray_Caster[(Player number of (Picked player))]
              • Trigger - Turn on Effect Ray <gen>
              • Trigger - Turn off (This trigger)
            • Else - Actions
              • Set Ray_Timer[(Player number of (Picked player))] = (Ray_Timer[(Player number of (Picked player))] + 0.05)
              • Set Ray_Damage[(Player number of (Picked player))] = (Ray_Damage[(Player number of (Picked player))] + (500.00 x 0.05))
              • Set Ray_Distance[(Player number of (Picked player))] = (Ray_Distance[(Player number of (Picked player))] + (750.00 x 0.05))
              • Unit - Create 1 Ray for (Picked player) at Ray_Point[(Player number of (Picked player))] facing Default building facing degrees
              • Unit - Add a (((Ray_Distance[(Player number of (Picked player))] / 100.00) x 0.08) + 0.10) second Generic expiration timer to (Last created unit)

  • Effect Ray
    • Events
      • Time - Every 0.04 seconds of game time
    • Conditions
    • Actions
      • Player Group - Pick every player in Ray_Casters and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between (Position of Ray_Caster[(Player number of (Picked player))]) and Ray_Point[(Player number of (Picked player))]) Greater than or equal to Ray_Distance[(Player number of (Picked player))]
            • Then - Actions
              • Player Group - Remove (Picked player) from Ray_Casters
              • Unit Group - Remove all units from Ray_Victims[(Player number of (Picked player))]
              • Custom script: call RemoveLocation (udg_Ray_Point[GetConvertedPlayerId(GetEnumPlayer())])
              • Trigger - Turn off (This trigger)
            • Else - Actions
              • Set Ray_Point[(Player number of (Picked player))] = (Ray_Point[(Player number of (Picked player))] offset by 50.00 towards Ray_Angle[(Player number of (Picked player))] degrees)
              • Unit - Create 1 Ray for (Picked player) at Ray_Point[(Player number of (Picked player))] facing Default building facing degrees
              • Unit - Add a (((Ray_Distance[(Player number of (Picked player))] / 100.00) x 0.08) + 0.10) second Generic expiration timer to (Last created unit)
              • Unit Group - Pick every unit in (Units within 150.00 of Ray_Point[(Player number of (Picked player))]) and do (Actions)
                • Loop - Actions
                  • Player Group - Pick every player in (All allies of (Owner of Ray_Caster[(Player number of (Picked player))])) and do (Actions)
                    • Loop - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • Or - Any (Conditions) are true
                            • Conditions
                              • (Owner of (Picked unit)) Not equal to (Picked player)
                        • Then - Actions
                          • Player Group - Pick every player in Ray_Casters and do (Actions)
                            • Loop - Actions
                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • (Owner of (Picked unit)) Not equal to (Owner of Ray_Caster[(Player number of (Picked player))])
                                  • ((Picked unit) is in Ray_Victims[(Player number of (Picked player))]) Equal to False
                                • Then - Actions
                                  • Unit - Cause Ray_Caster[(Player number of (Picked player))] to damage (Picked unit), dealing Ray_Damage[(Player number of (Picked player))] damage of attack type Spells and damage type Normal
                                  • Unit Group - Add (Picked unit) to Ray_Victims[(Player number of (Picked player))]
                                • Else - Actions
                        • Else - Actions
                          • Do nothing
Can someone take a look and give me some advice please? (or the leak-less versions)

I attached a map with this spell only and it does not lag, I suppose that it lags only on bigger maps.
 

Attachments

  • Ray.w3x
    22.1 KB · Views: 43
Last edited by a moderator:
Level 24
Joined
Mar 19, 2008
Messages
3,136
Those lines leak:
  • Set Ray_Point[(Player number of (Owner of (Casting unit)))] = ((Position of (Casting unit)) offset by 50.00 towards Ray_Angle[(Player number of (Owner of (Casting unit)))] degrees)
  • -------------
  • (Distance between (Position of Ray_Caster[(Player number of (Picked player))]) and Ray_Point[(Player number of (Picked player))]) Greater than or equal to Ray_Distance[(Player number of (Picked player))]
  • -------------
  • Unit Group - Pick every unit in (Units within 150.00 of Ray_Point[(Player number of (Picked player))]) and do (Actions)
Each time you see "Position of", it is reference to location which has to be stored and removed once not needed. With group, use either of methods presented in Things That Leak.

Your scripts quickly generate multiple leaks each second, however, the lag issue could be also caused by high rate of iterations with GroupEnum/ForGroup/CreateUnit functions. Usually we try to simplify algorithm/approach to achieve better efficiency e.g instead of creating 1 unit per target, create 1 dummy per iteration and apply timed life to it later, after all the casting is done.

Next, you spam calls left and right without actually storing data that is used throughout the code i.e (Casting unit), (Owner of (Casting unit)), (Picked Player). Use locals or globals - if u are more convenient with them - as a reference for such objects: e.g temp_u = (Triggering unit), temp_p = (Triggering player). And yes, you can use Triggering unit instead of casting. Same goes with player.
 
Top