HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Leaking trigger.... Can someone help fix?

08-15-2006, 01:41 PM#1
Preskooldude
I have a movement trigger (A more advanced one showcased on wc3sear.ch and I think on this site) that seems to be leaking badly (or it might be the fact that its called 67 times a minute). I was wondering if anyone could fix it please.
Trigger:
ActuallyMoving
Events
Conditions
Collapse Actions
Collapse For each (Integer A) from 1 to 6, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
((Player((Integer A))) slot status) Equal to Is playing
Collapse Then - Actions
-------- Down Left: 225 --------
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Collapse And - All (Conditions) are true
Collapse Conditions
M_UpKey_Down[(Integer A)] Equal to True
M_UpKey_Left[(Integer A)] Equal to True
Collapse Then - Actions
Set NextLoc = ((Position of PChar[(Integer A)]) offset by 100.00 towards 225.00 degrees)
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Terrain pathing at NextLoc of type Walkability is off) Equal to False
Collapse Then - Actions
Unit - Order PChar[(Integer A)] to Move To NextLoc
Collapse Else - Actions
Do nothing
Custom script: set udg_NextLoc = null
Custom script: call RemoveLocation(udg_NextLoc)
Collapse Else - Actions
-------- Down Right: 315 --------
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Collapse And - All (Conditions) are true
Collapse Conditions
M_UpKey_Down[(Integer A)] Equal to True
M_UpKey_Right[(Integer A)] Equal to True
Collapse Then - Actions
Set NextLoc = ((Position of PChar[(Integer A)]) offset by 100.00 towards 315.00 degrees)
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Terrain pathing at NextLoc of type Walkability is off) Equal to False
Collapse Then - Actions
Unit - Order PChar[(Integer A)] to Move To NextLoc
Collapse Else - Actions
Do nothing
Custom script: set udg_NextLoc = null
Custom script: call RemoveLocation(udg_NextLoc)
Collapse Else - Actions
-------- Up Left: 135 --------
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Collapse And - All (Conditions) are true
Collapse Conditions
M_UpKey_Up[(Integer A)] Equal to True
M_UpKey_Left[(Integer A)] Equal to True
Collapse Then - Actions
Set NextLoc = ((Position of PChar[(Integer A)]) offset by 100.00 towards 135.00 degrees)
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Terrain pathing at NextLoc of type Walkability is off) Equal to False
Collapse Then - Actions
Unit - Order PChar[(Integer A)] to Move To NextLoc
Collapse Else - Actions
Do nothing
Custom script: set udg_NextLoc = null
Custom script: call RemoveLocation(udg_NextLoc)
Collapse Else - Actions
-------- Up Right: 45 --------
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Collapse And - All (Conditions) are true
Collapse Conditions
M_UpKey_Up[(Integer A)] Equal to True
M_UpKey_Right[(Integer A)] Equal to True
Collapse Then - Actions
Set NextLoc = ((Position of PChar[(Integer A)]) offset by 100.00 towards 45.00 degrees)
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Terrain pathing at NextLoc of type Walkability is off) Equal to False
Collapse Then - Actions
Unit - Order PChar[(Integer A)] to Move To NextLoc
Collapse Else - Actions
Do nothing
Custom script: set udg_NextLoc = null
Custom script: call RemoveLocation(udg_NextLoc)
Collapse Else - Actions
-------- Up: 90 --------
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
M_UpKey_Up[(Integer A)] Equal to True
Collapse Then - Actions
Set NextLoc = ((Position of PChar[(Integer A)]) offset by 100.00 towards 90.00 degrees)
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Terrain pathing at NextLoc of type Walkability is off) Equal to False
Collapse Then - Actions
Unit - Order PChar[(Integer A)] to Move To NextLoc
Collapse Else - Actions
Do nothing
Custom script: set udg_NextLoc = null
Custom script: call RemoveLocation(udg_NextLoc)
Collapse Else - Actions
-------- Left: 180 --------
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
M_UpKey_Left[(Integer A)] Equal to True
Collapse Then - Actions
Set NextLoc = ((Position of PChar[(Integer A)]) offset by 100.00 towards 180.00 degrees)
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Terrain pathing at NextLoc of type Walkability is off) Equal to False
Collapse Then - Actions
Unit - Order PChar[(Integer A)] to Move To NextLoc
Collapse Else - Actions
Do nothing
Custom script: set udg_NextLoc = null
Custom script: call RemoveLocation(udg_NextLoc)
Collapse Else - Actions
-------- Down: 270 --------
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
M_UpKey_Down[(Integer A)] Equal to True
Collapse Then - Actions
Set NextLoc = ((Position of PChar[(Integer A)]) offset by 100.00 towards 270.00 degrees)
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Terrain pathing at NextLoc of type Walkability is off) Equal to False
Collapse Then - Actions
Unit - Order PChar[(Integer A)] to Move To NextLoc
Collapse Else - Actions
Do nothing
Custom script: set udg_NextLoc = null
Custom script: call RemoveLocation(udg_NextLoc)
Collapse Else - Actions
-------- Right: 0 --------
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
M_UpKey_Right[(Integer A)] Equal to True
Collapse Then - Actions
Set NextLoc = ((Position of PChar[(Integer A)]) offset by 100.00 towards 0.00 degrees)
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Terrain pathing at NextLoc of type Walkability is off) Equal to False
Collapse Then - Actions
Unit - Order PChar[(Integer A)] to Move To NextLoc
Collapse Else - Actions
Do nothing
Custom script: set udg_NextLoc = null
Custom script: call RemoveLocation(udg_NextLoc)
Collapse Else - Actions
Do nothing
Collapse Else - Actions
Do nothing
Wait 0.02 seconds
Trigger - Run (This trigger) (checking conditions)
Skip remaining actions
Can someone plz help me?
08-15-2006, 01:52 PM#2
n13astra
1. You use the following alot in the code;

Custom script: set udg_NextLoc = null
Custom script: call RemoveLocation(udg_NextLoc)

What your doing is setting the variable to null and then removing the location null. So it removes nothing!!! Swap these around.
08-15-2006, 01:58 PM#3
buttoxide
I think the call

set udg_NextLoc = null

is pretty much superfluous. You only null local variables because they will leak, but since you are continuously using this global variable, the previous value keeps getting overwritten so it's meaningless to null it.

My JASS isn't so hot though, anyone wanna verify my claim?
08-15-2006, 02:27 PM#4
Daelin
As far as I know, global variables do not need nullification because they are permanently available. Locals need nullification because once exiting the function, you can never use them and so, the place in memory is lost forever. In the case of the globals, you can reuse them.

~Daelin
08-15-2006, 03:17 PM#5
The)TideHunter(
Its possible to set variables to null in GUI, but its not needed.
You can null them if you feel like doing so.

NOTE: As n13astra pointed out, you are nulling then destroying.
Its complicated what nulling really does, unless you know about pointers.
Every handle variable has a pointer, (a unit is a handle, a timer is, anything but integer, string, boolean, real and code).
And when you set a handle to something.
Like:
Trigger:
set MyUnit = Last created unit

Its really making a pointer that points to the last created unit.

Thats a pointer explanation.
Now when you destroy the variable, you are destroying the thing that the pointer points to.
So for example, a timer, if you type:
Collapse JASS:
    call DestroyTimer(MyTimer)
Its really pointing to the actuall timer.

When you null the variable, you destroy the pointer, so it points to nothing.

If you null then destroy, the actual thing it pointing too is lost, you cant destroy it because its not pointing to anything.
So destroy then remove the pointer.
08-16-2006, 12:24 AM#6
Preskooldude
In any case, the trigger was still leaking (Yes I made sure it was this trigger) for some reason...
It'd be okay the first 75 tiems u used it, then the next 30 times it'd begin to slow the comp down, until the music became all shaky and stuff...
I'll switch them around.... lets see if that works :D

Just tested it. Yes its still leaking (For reasons unknown) and I have no idea why.... is there anyone who can find out why?
08-17-2006, 01:38 AM#7
PipeDream
First read the rules.
Then post the current version of the trigger or edit the top post.
08-17-2006, 04:24 AM#8
n13astra
Firstly, these last 3 lines i have no idea why youve done it like that but I would change it to use events.

Trigger:
Wait 0.02 seconds
Trigger - Run (This trigger) (checking conditions)
Skip remaining actions

Skip remaining actions does nothing at all where you have put it.

Secondly, If youve made those changes i suggested, then this trigger is no longer leaking. So i would look else where because this aint it.
08-17-2006, 06:39 AM#9
The_AwaKening
Like they said, remove the set to null completely. It's not needed. Also, this might help eliminate more leaking.

This code needs another variable stored:
Trigger:
Set NextLoc = ((Position of PChar[(Integer A)]) offset by 100.00 towards 135.00 degrees)
Make another location variable and set the Position of PChar[Integer A] to that variable and remove it also when done. Would look something like this...
Trigger:
Set tempLoc = Position of PChar[Integer A]
Set NextLoc = tempLoc offset by 100.00 towards 135.00 degrees)

Then like I said, make sure to remove both locations.