| 12-11-2004, 01:32 AM | #1 |
Can someone check my trigger for memory leaks or any other problem, I can't find anything, the trigger uses pretty much memory for the 30 second it's active. The trigger is working as it should, but the memory increases with 1-2mb everytime it runs. Code:
function StarConditions takes nothing returns boolean
if ( not ( GetSpellAbilityId() == 'A007' ) ) then
return false
endif
return true
endfunction
function CarEffect takes nothing returns nothing
call SetUnitVertexColorBJ( udg_UnitStar[GetHandleInt4(GetTriggeringTrigger(),"index4")], GetRandomReal(0, 100.00), GetRandomReal(0, 100.00), GetRandomReal(0, 100.00), 0 )
endfunction
function PickedUnit takes nothing returns boolean
local unit u
local unit y
local integer i
set u = GetFilterUnit()
set i = GetConvertedPlayerId(GetOwningPlayer(u))
set y = udg_UnitStar[GetHandleInt4(GetTriggeringTrigger(),"index4")]
if ( GetUnitTypeId(u) == 'hmtt' and u != y and udg_BoolStar[i] == false and udg_PlayerSpeed[i] < 40) then
set u = null
set y = null
return true
else
set u = null
set y = null
return false
endif
endfunction
function Flyaway takes nothing returns nothing
local integer i
local unit u
local effect e
set u = GetEnumUnit()
set i = GetConvertedPlayerId(GetOwningPlayer(u))
set udg_PlayerCarAngle[i] = GetRandomReal(0, 360.00)
set udg_PlayerSpeed[i] = ( udg_PlayerSpeed[i] + 15.00 )
call AddSpecialEffectTargetUnitBJ( "origin", u, "Objects\\Spawnmodels\\NightElf\\NEDeathMedium\\NEDeath.mdl" )
set e = GetLastCreatedEffectBJ()
call PolledWait( 0.50 )
call DestroyEffectBJ( e )
set u = null
endfunction
function CarMoveRegion takes nothing returns nothing
local location l
local group g
local unit u
local integer i
local integer r
set r = GetHandleInt4(GetTriggeringTrigger(),"index4")
set g = GetUnitsInRectMatching(udg_RectStar[r], Condition(function PickedUnit))
set l = GetUnitLoc(udg_UnitStar[r])
call MoveRectToLoc( udg_RectStar[r] , l )
call ForGroupBJ( g, function Flyaway )
call RemoveLocation (l)
call DestroyGroup(g)
set l = null
set u = null
set g = null
endfunction
function StarActions takes nothing returns nothing
local location l
local effect e
local trigger t
local trigger t2
local integer i
set udg_IntStar = udg_IntStar + 1
set i = GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))
if ( udg_BoolStar[i] == false ) then
set t = CreateTrigger()
set t2 = CreateTrigger()
set l = GetUnitLoc(GetTriggerUnit())
set udg_RealAcceleration1[i] = 1.7
set udg_RealAcceleration2[i] = 1.5
set udg_RealAcceleration3[i] = 1.2
set udg_RealAcceleration4[i] = 1
set udg_RealAcceleration5[i] = 0.7
set udg_MaxSpeed[i] = 25
set udg_BoolStar[i] = true
set udg_RectStar[i] = RectFromCenterSizeBJ(l, 400.00, 400.00)
set udg_UnitStar[i] = GetTriggerUnit()
call AddSpecialEffectTargetUnitBJ( "chest", udg_UnitStar[i], "Abilities\\Spells\\NightElf\\FaerieDragonInvis\\FaerieDragon_Invis.mdl" )
set e = GetLastCreatedEffectBJ()
call MoveRectToLoc( udg_RectStar[i], l )
call SetHandleInt4(t,"index4",i)
call SetHandleInt4(t2,"index4",i)
set udg_BoolUnitHaveItem[i] = false
call UnitRemoveAbilityBJ( 'A007', GetTriggerUnit() )
call TriggerRegisterTimerEventPeriodic( t2, 0.05 )
call TriggerAddAction( t2, function CarEffect )
call TriggerRegisterTimerEventPeriodic( t, 0.03 )
call TriggerAddAction( t, function CarMoveRegion )
call PolledWait( 30 )
call DestroyTrigger( t )
call DestroyTrigger( t2 )
set udg_BoolStar[i] = false
set udg_RealAcceleration1[i] = 0.7
set udg_RealAcceleration2[i] = 0.5
set udg_RealAcceleration3[i] = 0.3
set udg_RealAcceleration4[i] = 0.15
set udg_RealAcceleration5[i] = 0.05
set udg_MaxSpeed[i] = 19
call PolledWait( 1 )
call SetUnitVertexColorBJ( udg_UnitStar[i], 100, 100, 100, 0 )
call DestroyEffectBJ( e )
else
endif
endfunction
//===========================================================================
function InitTrig_Cast_Star takes nothing returns nothing
set gg_trg_Cast_Star = CreateTrigger( )
call TriggerRegisterPlayerUnitEventSimple( gg_trg_Cast_Star, Player(0), EVENT_PLAYER_UNIT_SPELL_CAST )
call TriggerRegisterPlayerUnitEventSimple( gg_trg_Cast_Star, Player(1), EVENT_PLAYER_UNIT_SPELL_CAST )
call TriggerRegisterPlayerUnitEventSimple( gg_trg_Cast_Star, Player(2), EVENT_PLAYER_UNIT_SPELL_CAST )
call TriggerRegisterPlayerUnitEventSimple( gg_trg_Cast_Star, Player(3), EVENT_PLAYER_UNIT_SPELL_CAST )
call TriggerAddCondition( gg_trg_Cast_Star, Condition( function StarConditions ) )
call TriggerAddAction( gg_trg_Cast_Star, function StarActions )
endfunction
|
| 12-11-2004, 02:35 AM | #2 | |
1. Code:
function StarConditions takes nothing returns boolean
if ( not ( GetSpellAbilityId() == 'A007' ) ) then
return false
endif
return true
endfunctionThe following function does the exact same thing but takes up less space. Always look at trigger converted from GUI to JASS for they're often inificiant. Code:
function StarConditions takes nothing returns boolean return GetSpellAbilityId()=='A007' endfunction 2. Code:
function CarEffect takes nothing returns nothing
call SetUnitVertexColorBJ( udg_UnitStar[GetHandleInt4([color=red][b]GetTriggeringTrigger()[/b][/color],"index4")], GetRandomReal(0, 100.00), GetRandomReal(0, 100.00), GetRandomReal(0, 100.00), 0 )
endfunctionQuote:
Since a player extends a handle, it does leak, but you don't need to worry about players unless you have a trigger with a player leak that fires like at least 2 times every minutes 3. Code:
function StarActions takes nothing returns nothing
[color=red][b] local location l
local effect e
local trigger t
local trigger t2[/b][/color]
local integer i
set udg_IntStar = udg_IntStar + 1
set i = GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))
if ( udg_BoolStar[i] == false ) then
set t = CreateTrigger()
set t2 = CreateTrigger()
set l = GetUnitLoc(GetTriggerUnit())
set udg_RealAcceleration1[i] = 1.7
set udg_RealAcceleration2[i] = 1.5
set udg_RealAcceleration3[i] = 1.2
set udg_RealAcceleration4[i] = 1
set udg_RealAcceleration5[i] = 0.7
set udg_MaxSpeed[i] = 25
set udg_BoolStar[i] = true
set udg_RectStar[i] = RectFromCenterSizeBJ(l, 400.00, 400.00)
set udg_UnitStar[i] = GetTriggerUnit()
call AddSpecialEffectTargetUnitBJ( "chest", udg_UnitStar[i], "Abilities\\Spells\\NightElf\\FaerieDragonInvis\\FaerieDragon_Invis.mdl" )
set e = GetLastCreatedEffectBJ()
call MoveRectToLoc( udg_RectStar[i], l )
call SetHandleInt4(t,"index4",i)
call SetHandleInt4(t2,"index4",i)
set udg_BoolUnitHaveItem[i] = false
call UnitRemoveAbilityBJ( 'A007', GetTriggerUnit() )
call TriggerRegisterTimerEventPeriodic( t2, 0.05 )
call TriggerAddAction( t2, function CarEffect )
call TriggerRegisterTimerEventPeriodic( t, 0.03 )
call TriggerAddAction( t, function CarMoveRegion )
call PolledWait( 30 )
call DestroyTrigger( t )
call DestroyTrigger( t2 )
set udg_BoolStar[i] = false
set udg_RealAcceleration1[i] = 0.7
set udg_RealAcceleration2[i] = 0.5
set udg_RealAcceleration3[i] = 0.3
set udg_RealAcceleration4[i] = 0.15
set udg_RealAcceleration5[i] = 0.05
set udg_MaxSpeed[i] = 19
call PolledWait( 1 )
call SetUnitVertexColorBJ( udg_UnitStar[i], 100, 100, 100, 0 )
call DestroyEffectBJ( e )
endif
endfunctionThose are never set to null. TIP: The only time you need parenthasees is when calling a function. TIP: You do not need spaces between parameters when calling a function. (ex: call aFunction(integer,unit,boolean) instead of call aFunction( integer, unit, boolean ) TIP: You do not have to put "==true" after boolexprs if you need to check if something is true. TIP: Instead of putting "if not boolexpr==false", put "if boolexpr". It does the same thing because the first string sees if something is false, which is the same thing as checking if something is true. TIP: You can use loops in trigger initialization functions. |
| 12-11-2004, 01:42 PM | #3 |
thanks for your answer, but I don't belive changing that stuff will help so much. ofcourse you could change the condition statement, but the condition as it is will not have any effect on the memory, well a very very small one which you wont even notice. the same about the boolexpr, it does'nt realy matter how you write it, could change it but it would only be less text, no important change in memory usage. Yes, the locations and triggers leak in the main function, but they are only created when the trigger runs, which it don't very often. I will ofcourse take care of that memory leak to, but it's not so important. I think the big problem is in the move region and car effect function, where I use GetHandleInt4(GetTriggeringTrigger(),"index4") since both those function, runs every 0.03 and 0.05 sec for 30 seconds. Im not at my computer where I have wc now so I cant test , but since it uses GetTriggeringTrigger, that one will leak as u said right? Or does the hole GetHandleInt function leak? it also uses a "Get" function. If I do this. local trigger t set t = GetTriggeringTrigger GetHandleInt4( t, "index4") blablabal set t = null would that help? or is the problem somewhere else? Thanks for your tips and help. |
| 12-11-2004, 01:49 PM | #4 |
Post that GetHandleInt4 function. That could be waht's causing the leak. |
| 12-11-2004, 04:34 PM | #5 | |
Quote:
The leak is caused in one of those functions, CarMoveRegion is a function that runs every 0.03 second. But I can't figure out what it is. The GetHandleInt function is not leaking. Code:
function PickedUnit takes nothing returns boolean
local unit u
local unit y
local integer i
set u = GetFilterUnit()
set i = GetConvertedPlayerId(GetOwningPlayer(u))
set y = udg_UnitStar[GetHandleInt4(GetTriggeringTrigger(),"index4")]
if ( GetUnitTypeId(u) == 'hmtt' and u != y and udg_BoolStar[i] == false and udg_PlayerSpeed[i] < 40) then
set u = null
set y = null
return true
else
set u = null
set y = null
return false
endif
endfunction
function Flyaway takes nothing returns nothing
local integer i
local unit u
local effect e
set u = GetEnumUnit()
set i = GetConvertedPlayerId(GetOwningPlayer(u))
set udg_PlayerCarAngle[i] = GetRandomReal(0, 360.00)
set udg_PlayerSpeed[i] = ( udg_PlayerSpeed[i] + 15.00 )
call AddSpecialEffectTargetUnitBJ( "origin", u, "Objects\\Spawnmodels\\NightElf\\NEDeathMedium\\NEDeath.mdl" )
set e = GetLastCreatedEffectBJ()
call PolledWait( 0.50 )
call DestroyEffectBJ( e )
set u = null
endfunction
function CarMoveRegion takes nothing returns nothing
local location l
local group g
local unit u
local integer i
local integer r
set r = GetHandleInt4(GetTriggeringTrigger(),"index4")
set g = GetUnitsInRectMatching(udg_RectStar[r], Condition(function PickedUnit))
set l = GetUnitLoc(udg_UnitStar[r])
call MoveRectToLoc( udg_RectStar[r] , l )
call ForGroupBJ( g, function Flyaway )
call RemoveLocation (l)
call DestroyGroup(g)
set l = null
set u = null
set g = null
endfunction
|
| 12-11-2004, 04:49 PM | #6 |
Code:
function CarMoveRegion takes nothing returns nothing
local location l
local group g
local unit u
local integer i
local integer r
set r = GetHandleInt4(GetTriggeringTrigger(),"index4")
set g = GetUnitsInRectMatching(udg_RectStar[r], [color=red][b]Condition(function PickedUnit)[/b][/color])
set l = GetUnitLoc(udg_UnitStar[r])
call MoveRectToLoc( udg_RectStar[r] , l )
call ForGroupBJ( g, function Flyaway )
call RemoveLocation (l)
call DestroyGroup(g)
set l = null
set u = null
set g = null
endfunctionI'm not sure about this but try using a local conditionfunc instead and set it to null at the end even though conditionfunc extends boolexpr not handle. EDIT: I just looked at common.j and boolexpr extends handle so conditionfunc is a child of a handle. |
| 12-11-2004, 08:45 PM | #7 | |
Quote:
Code:
function Flyaway takes nothing returns nothing
local integer i
local unit u
local effect e
set u = GetEnumUnit()
set i = GetConvertedPlayerId(GetOwningPlayer(u))
set udg_PlayerCarAngle[i] = GetRandomReal(0, 360.00)
set udg_PlayerSpeed[i] = ( udg_PlayerSpeed[i] + 15.00 )
call AddSpecialEffectTargetUnitBJ( "origin", u, "Objects\\Spawnmodels\\NightElf\\NEDeathMedium\\NED eath.mdl" )
set e = GetLastCreatedEffectBJ()
[color=Red] call PolledWait( 0.50 )[/color]
call DestroyEffectBJ( e )
set u = null
endfunctionI think by getting rid of the wait you will get rid of the leak. |
| 12-14-2004, 02:00 PM | #8 |
Thanks for your help, I removed the wait, did'nt need it, the effect were created visually even if I destroyed it directly after I had created it. I also did'nt use a global cache, when I changed that and a couple of other things it worked out well, though there still seems to be a memoryleak somewhere, the code looks clean, maybe cause the trigger is kind of heavy and runs every 0.03 sec, a minor leak is inevitable. |
