• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece!🔗 Click here to enter!

Fixing Leaks

Status
Not open for further replies.
Level 7
Joined
Feb 13, 2022
Messages
86
So I know my map leaks quite a bit, so I want to clean it up. Problem is I'm having trouble identifying what triggers of mine are causing the leaks. The other problem I'm having is using the correct custom script to fix the leaks. Here is all the triggers I think that are causing leaks, please let me know which triggers are leaking and what is the correct script to use. Thank you to all who help with this :)!!!



trigger leak 1.PNG



trigger leak 2.PNG


trigger leak 3.PNG



trigger leak 4.PNG


trigger leak 5.PNG


trigger leak 6.PNG



PS... Sorry for all the different triggers, I just wanted to make sure I had all my bases covered.
 
Level 39
Joined
Feb 27, 2007
Messages
5,031
This should explain what to do and links to another tutorial that explains why.
 
Level 7
Joined
Feb 13, 2022
Messages
86
This should explain what to do and links to another tutorial that explains why.
Yeah I tried this thread and the other one they link. But it didn't help me, none of the stuff they said to do allowed me to save.. I might have overlooked something on these treads. 🤷‍♂️
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,583
Yeah I tried this thread and the other one they link. But it didn't help me, none of the stuff they said to do allowed me to save.. I might have overlooked something on these treads. 🤷‍♂️
You probably typed something wrong in the Custom Script. It's case sensitive and if you miss one little thing it won't work. Also, the errors you receive will usually tell you what you did wrong. Sometimes the error message will even suggest a solution -> "Did you mean to type X?". The Editor is trying to help you fix your mistake, but it's definitely not perfect.

Anyway, here's an example that may help.

When trying to get rid of Point leaks you would use this function:
  • Custom script: call RemoveLocation()
Then inside of the parenthesis () you would put the name of your Point variable:
  • Custom script: call RemoveLocation(udg_MyPointVariable)
In this case my Point variable is named MyPointVariable.

Another important thing to remember is that when using Custom Script your variables must have the "_udg" prefix before their name. This basically tells the Editor that you're talking about a GUI variable and not a Jass variable.

So the end result could look something like this example. Here I am creating a Unit and cleaning up the memory leak involved:
  • Set Variable MyPointVariable = (Center of playable map area)
  • Unit - Create 1 Footman for Player 1 at MyPointVariable
  • Custom script: call RemoveLocation(udg_MyPointVariable)
This same logic applies to Unit Group / Player Group destruction. But for those you use a different function:
  • Custom script: call DestroyGroup(udg_MyUnitGroupVariable)
  • Custom script: call DestroyForce(udg_MyPlayerGroupVariable)
You'll find that Points / Unit Groups are the most common leaks you'll be creating and thus I would focus on cleaning those up first.
 
Last edited:
Level 7
Joined
Feb 13, 2022
Messages
86
You probably typed something wrong in the Custom Script. It's case sensitive and if you miss one little thing it won't work. Also, the errors you receive will usually tell you what you did wrong. Sometimes the error message will even suggest a solution -> "Did you mean to type X?". The Editor is trying to help you fix your mistake, but it's definitely not perfect.

Anyway, here's an example that may help.

When trying to get rid of Point leaks you would use this function:
  • Custom script: call RemoveLocation()
Then inside of the parenthesis () you would put the name of your Point variable:
  • Custom script: call RemoveLocation(udg_MyPointVariable)
In this case my Point variable is named MyPointVariable.

Another important thing to remember is that when using Custom Script your variables must have the "_udg" prefix before their name. This basically tells the Editor that you're talking about a GUI variable and not a Jass variable.

So the end result could look something like this example. Here I am creating a Unit and cleaning up the memory leak involved:
  • Set Variable MyPointVariable = (Center of playable map area)
  • Unit - Create 1 Footman for Player 1 at MyPointVariable
  • Custom script: call RemoveLocation(udg_MyPointVariable)
This same logic applies to Unit Group / Player Group destruction. But for those you use a different function:
  • Custom script: call DestroyGroup(udg_MyUnitGroupVariable)
  • Custom script: call DestroyForce(udg_MyPlayerGroupVariable)
You'll find that Points / Unit Groups are the most common leaks you'll be creating and thus I would focus on cleaning those up first.
Sweet I will try all of this out ty!
Hey did you notice if these triggers cause leaks?
 
Level 7
Joined
Feb 13, 2022
Messages
86
Yeah, they all do. You're leaking Points with your Unit creation and Unit Groups when you do things like "Units in..." or "Pick every unit of type / owned by...".
Awesome, I figured they all did. Just wanted a second opinion on it! For the leaking points, do I need to make variables for each unit creation to be able to fix the leak? Or can I just use script to fix the leaks and if I can do it without variable, what would that look like?
Sorry for all the dumb questions, I appreciate all your consistent help you have offered throughout the months :) !!
 
Level 7
Joined
Feb 13, 2022
Messages
86
Awesome, I figured they all did. Just wanted a second opinion on it! For the leaking points, do I need to make variables for each unit creation to be able to fix the leak? Or can I just use script to fix the leaks and if I can do it without variable, what would that look like?
Sorry for all the dumb questions, I appreciate all your consistent help you have offered throughout the months :) !!
Also does creating items create point leaks? Would the script be the same as the creation of regular units script?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,583
Yes, but it's not the Unit/Item that causes the leak, it's the fact that you're creating an object somewhere in the game world without using a Point variable to define that "somewhere".

The rule of thumb for Point leaks is this:
If you see the words "Position of X", "Center of Region X", "Random point in Region X", WITHOUT a Variable being Set, know that you're creating a memory leak. Also, when Setting a Point variable, you MUST destroy it before Setting it again, otherwise you will create a leak.

The solution is to Set your own Point variables at these places and then reference those instead:
  • Set Variable MyPoint = (Position of (Triggering unit))
  • Set Variable MyPoint = (Center of Region X)
  • Set Variable MyPoint = (Random point in Region X)
That above trigger actually leaks though, due to us breaking the second part of the rule of thumb about needing to destroy before setting again.

Now it doesn't leak since we're following the rule of thumb:
  • Set Variable MyPoint = (Position of (Triggering unit))
  • Custom script: call RemoveLocation(udg_MyPoint)
  • Set Variable MyPoint = (Center of Region X)
  • Custom script: call RemoveLocation(udg_MyPoint)
  • Set Variable MyPoint = (Random point in Region X)
  • Custom script: call RemoveLocation(udg_MyPoint)
Now how would we apply this to our triggers? Easy, for example this trigger is completely leak free:
  • Set Variable MyPoint = (Position of (Triggering unit))
  • Unit - Create 1 Footman for Player 1 at MyPoint
  • Custom script: call RemoveLocation(udg_MyPoint)
  • Set Variable MyPoint = (Center of Region X)
  • Item - Create 1 Boots of Speed at MyPoint
  • Custom script: call RemoveLocation(udg_MyPoint)
  • Set Variable MyPoint = (Random point in Region X)
  • Floating Text - Create floating text at MyPoint
  • Custom script: call RemoveLocation(udg_MyPoint)
Note how I am using the same Point variable throughout this trigger. This is fine since I'm making sure to Destroy it before Setting it again. Also, note how the Point variable can be used in all sorts of different Actions. There's a lot of different things that you can create at a Point, not just Units and Items, and you must always follow the rule of thumb for these.

Another important thing to note as some users get confused about this. Sometimes you will Set a Point or Unit Group that you intend to Set ONCE and then use for the rest of the game. In those cases, you don't have to worry about Destroying them because they're intended to exist forever. For example, let's say that there's a Region where your Heroes spawn/respawn at, and this could happen multiple times throughout the game. Instead of creating/using/removing a temporary Point at that Region again and again, you could just create a permanent Point there and re-use it forever. In this case the Point would use a unique variable and get Set once and ONLY once, most likely during Map Initialization while everything is still loading, that way you can reference it in your triggers knowing that it's been Set beforehand.

Maybe this explanation will help you understand why memory leaks are even an issue in the first place:
Anytime the game is asking for a location in the world and you aren't referencing a Point variable, the game creates a Point variable for you. This Point variable that it creates is never Destroyed and thus becomes what's known as a memory leak. It's something that will exist forever even though it's no longer needed. That's why you need to take the extra steps to use your own Point variables and manually Destroy them yourself. You're basically throwing away the garbage that Blizzard failed to clean up themselves. This same logic applies to the other types of leaks as well.
 
Last edited:
Level 7
Joined
Feb 13, 2022
Messages
86
Yes, but it's not the Unit/Item that causes the leak, it's the fact that you're creating an object somewhere in the world without using a Point variable to define that "somewhere".

The rule of thumb for Point leaks is this:

If you see the words "Position of X", "Center of Region X", "Random point in Region X", WITHOUT a Variable being Set, know that you're creating a memory leak. Also, when Setting a Point variable, you MUST destroy it before Setting it again, otherwise you will create a leak.

The solution is to Set your own Point variables at these places and then reference those instead:
  • Set Variable MyPoint = (Position of (Triggering unit))
  • Set Variable MyPoint = (Center of Region X)
  • Set Variable MyPoint = (Random point in Region X)
That above trigger actually leaks though, due to us breaking the second part of the rule of thumb about needing to destroy before setting again.

Now it doesn't leak since we're following the rule of thumb:
  • Set Variable MyPoint = (Position of (Triggering unit))
  • Custom script: call RemoveLocation(udg_MyPoint)
  • Set Variable MyPoint = (Center of Region X)
  • Custom script: call RemoveLocation(udg_MyPoint)
  • Set Variable MyPoint = (Random point in Region X)
  • Custom script: call RemoveLocation(udg_MyPoint)
Now how would we apply this to our triggers? Easy, this trigger is completely leak free:
  • Set Variable MyPoint = (Position of (Triggering unit))
  • Unit - Create 1 Footman for Player 1 at MyPoint
  • Custom script: call RemoveLocation(udg_MyPoint)
  • Set Variable MyPoint = (Center of Region X)
  • Item - Create 1 Boots of Speed at MyPoint
  • Custom script: call RemoveLocation(udg_MyPoint)
  • Set Variable MyPoint = (Random point in Region X)
  • Floating Text - Create floating text at MyPoint
  • Custom script: call RemoveLocation(udg_MyPoint)
There's a lot of different things that you can Create at a Point in Warcraft 3, not just Units and Items. You must always follow the rule of thumb for these.

Another important thing to note as some users get confused about this. Sometimes you will Set a Point or Unit Group that you intend to Set ONCE and then use for the rest of the game. In those cases, you don't have to worry about Destroying them because they're intended to exist forever. For example, let's say that there's a Region where your Heroes spawn/respawn at, and this happened multiple times throughout the game. Instead of creating/using/removing a temporary Point again and again at that Region, you could just create a permanent Point there and re-use it forever. In this case the Point would use a unique variable and get Set once and ONLY once, most likely during Map Initialization while everything is still loading.

Maybe this explanation will help you understand why memory leaks are even an issue:
Anytime the game is asking for a location in the world and you aren't referencing a Point variable, the game creates a Point variable for you. This Point variable that it creates is never Destroyed and thus becomes what's known as a memory leak. It's something that will exist forever even though it's no longer needed. That's why you need to take the extra steps to use your own Point variables and manually Destroy them yourself. You're basically throwing away the garbage that Blizzard failed to clean up themselves.
This is straight up fantastic! This is like the wiki for leaks in Warcraft. Thank you for this, this helps clear up what causes leaks and how to fix them! Tomorrow I will try all of this out, I will let you know if I have any more questions! Thank you again.
 
Status
Not open for further replies.
Top