• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Leak in Custom Spell "Charge/Rush Towards"

Status
Not open for further replies.
Level 4
Joined
Jul 5, 2009
Messages
41
Hi, I'm having a problem with memory leaks. I'm pretty experienced with GUI triggering, and I've worked on minimizing memory leaks for quite some time now (and somewhat succesful). Theoretically, these triggers should not create any memory leaks (according to my knowledge). However I see a drastic drop in framerate simply by this spell being cast once.
I've tried to replicate a kind of "charge/rush towards a point"-spell. I call upon you guys' expertise to identify the problem. Any further secrets in erasing memory leaks would be appreciated, however this is not my main problem, thanks in advance.
  • Charge
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Slide
    • Actions
      • Unit Group - Add (Triggering unit) to ChargeUnitGroup
      • Unit - Turn collision for (Triggering unit) Off
      • Set ChargePoint[1] = (Target point of ability being cast)
      • Trigger - Turn on Charge loop <gen>
  • Charge loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in ChargeUnitGroup and do (Actions)
        • Loop - Actions
          • Set ChargePoint[2] = (Position of (Picked unit))
          • Set ChargePoint[3] = (ChargePoint[2] offset by 13.00 towards (Angle from ChargePoint[2] to ChargePoint[1]) degrees)
          • Unit - Move (Picked unit) instantly to ChargePoint[3]
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between ChargePoint[2] and ChargePoint[1]) Less than or equal to 13.00
            • Then - Actions
              • Unit Group - Remove (Picked unit) from ChargeUnitGroup
              • Unit - Turn collision for (Picked unit) On
              • Custom script: call RemoveLocation(udg_ChargePoint[1])
              • Custom script: call RemoveLocation(udg_ChargePoint[2])
              • Custom script: call RemoveLocation(udg_ChargePoint[3])
              • Trigger - Turn off (This trigger)
            • Else - Actions
              • Custom script: call RemoveLocation(udg_ChargePoint[2])
              • Custom script: call RemoveLocation(udg_ChargePoint[3])
 
Level 4
Joined
Jul 5, 2009
Messages
41
Yeah sorry, the unit group is being erased, I forgot to add that in.
  • Custom script: call DestroyGroup(udg_ChargeUnitGroup)
Edit: Added in the following way in the trigger:
  • Charge loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in ChargeUnitGroup and do (Actions)
        • Loop - Actions
          • Set ChargePoint[2] = (Position of (Picked unit))
          • Set ChargePoint[3] = (ChargePoint[2] offset by 13.00 towards (Angle from ChargePoint[2] to ChargePoint[1]) degrees)
          • Unit - Move (Picked unit) instantly to ChargePoint[3]
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between ChargePoint[2] and ChargePoint[1]) Less than or equal to 13.00
            • Then - Actions
              • Unit Group - Remove (Picked unit) from ChargeUnitGroup
              • Unit - Turn collision for (Picked unit) On
              • Custom script: call RemoveLocation(udg_ChargePoint[1])
              • Custom script: call RemoveLocation(udg_ChargePoint[2])
              • Custom script: call RemoveLocation(udg_ChargePoint[3])
              • Custom script: call DestroyGroup(udg_ChargeUnitGroup)
              • Trigger - Turn off (This trigger)
            • Else - Actions
              • Custom script: call RemoveLocation(udg_ChargePoint[2])
              • Custom script: call RemoveLocation(udg_ChargePoint[3])
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
From the looks of it, you don't need to use call DestroyGroup(udg_ChargeUnitGroup). You only need to destroy it if you were creating another group with it, but all you're doing is adding units to it on cast and removing them when the instance is over.

With all that considered, I would simplify your trigger to this:
  • Charge loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in ChargeUnitGroup and do (Actions)
        • Loop - Actions
          • Set ChargePoint[2] = (Position of (Picked unit))
          • Set ChargePoint[3] = (ChargePoint[2] offset by 13.00 towards (Angle from ChargePoint[2] to ChargePoint[1]) degrees)
          • Unit - Move (Picked unit) instantly to ChargePoint[3]
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between ChargePoint[2] and ChargePoint[1]) Less than or equal to 13.00
            • Then - Actions
              • Unit Group - Remove (Picked unit) from ChargeUnitGroup
              • Unit - Turn collision for (Picked unit) On
              • Custom script: call RemoveLocation(udg_ChargePoint[1])
              • Trigger - Turn off (This trigger)
            • Else - Actions
          • Custom script: call RemoveLocation(udg_ChargePoint[2])
          • Custom script: call RemoveLocation(udg_ChargePoint[3])

For added efficiency, you can store (Picked unit) into a unit variable, and (Angle from ChargePoint[2] to ChargePoint[1]) into a real variable on cast.
 
Status
Not open for further replies.
Top