• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] This map leaks.

Status
Not open for further replies.
Level 1
Joined
Jun 5, 2007
Messages
3
This map has memory leak trouble, I've tried fixing it but my methods result in the map's grenade not working right at all. If anybody can fix it or tell me how to without affecting the grenade, I'll throw out rep points like crazy. The most important trigger is called Gex, it's also the one that glitched the grenade when i tried cleaning the memory leaks. Help with the other leaky triggers would be good too, the jass ones seem ok, but the gui ones leak. Open the attachment map to get a better grasp of the script/variables.
This is not my map but I use it as the foundation for my maps, credits go to jigs4w for the map, infrane for the particle system, and anitarf for vector.

Here is the jass grenade trigger.
JASS:
function Trig_ThrowGrenade_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'AOfs'
endfunction

function Trig_ThrowGrenade_Actions takes nothing returns nothing
local location casterpos = GetUnitLoc(GetSpellAbilityUnit())
local location topos = GetSpellTargetLoc()
local unit u = CreateParticle(GetOwningPlayer(GetSpellAbilityUnit()),'hfoo',GetLocationX(casterpos),GetLocationY(casterpos),GetUnitFacing(GetSpellAbilityUnit()))
call ParticleSetSpeed(u,GetLocationX(topos)-GetLocationX(casterpos),GetLocationY(topos)-GetLocationY(casterpos),1200)
call ParticleLinkConditionTrigger2Func(u, ParticleGroundHit(), "GroundHit_Bounce")
call ParticleLinkConditionTrigger2Func(u, ParticleDeath(), "Death_Remove")
call ParticleAddForce(u, G())
call RemoveLocation(casterpos)
call RemoveLocation(topos)
set casterpos=null
set topos=null
set u = null
endfunction

//===========================================================================
function InitTrig_ThrowGrenade takes nothing returns nothing
    set gg_trg_ThrowGrenade = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_ThrowGrenade, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_ThrowGrenade, Condition( function Trig_ThrowGrenade_Conditions ) )
    call TriggerAddAction( gg_trg_ThrowGrenade, function Trig_ThrowGrenade_Actions )
endfunction

and here is the gui trigger Gex, it's leaky. I put it in jass here. be wary of cleaning the leaks in this one, it might glitch the grenade.
JASS:
function Trig_Gex_Conditions takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'hfoo' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Gex_Actions takes nothing returns nothing
    call AddSpecialEffectLocBJ( GetUnitLoc(GetTriggerUnit()), "Objects\\Spawnmodels\\Other\\NeutralBuildingExplosion\\NeutralBuildingExplosion.mdl" )
    call UnitDamagePointLoc( GetTriggerUnit(), 0, 200.00, GetUnitLoc(GetTriggerUnit()), 100, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
endfunction

//===========================================================================
function InitTrig_Gex takes nothing returns nothing
    set gg_trg_Gex = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Gex, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Gex, Condition( function Trig_Gex_Conditions ) )
    call TriggerAddAction( gg_trg_Gex, function Trig_Gex_Actions )
endfunction
 

Attachments

  • Real BulletGrenade.w3x
    214.3 KB · Views: 103
1. I don't use the Particle system, so I don't know if it leaks.

2. Change it to this code:
JASS:
function Trig_Gex_Conditions takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit()) == 'hfoo'
endfunction

function Trig_Gex_Actions takes nothing returns nothing
    local location trigloc = GetUnitLoc(GetTriggerUnit())
    call DestroyEffect(AddSpecialEffectLoc("Objects\\Spawnmodels\\Other\\NeutralBuildingExplosion\\NeutralBuildingExplosion.mdl", trigloc))
    call UnitDamagePointLoc(GetTriggerUnit(), 0, 200.00, trigloc, 100, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
    call RemoveLocation(trigloc)
    set trigloc = null
endfunction

//===========================================================================
function InitTrig_Gex takes nothing returns nothing
    set gg_trg_Gex = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Gex, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Gex, Condition( function Trig_Gex_Conditions ) )
    call TriggerAddAction( gg_trg_Gex, function Trig_Gex_Actions )
endfunction

I hope this helps! :smile:
 
Level 1
Joined
Jun 5, 2007
Messages
3
Thanks, that's helpful. Anyone see any leaks in these two triggers? They control the sniper bullets, and are a little different from the attachment map because I tried fixing the leaks myself. Not sure if they are leaky or if it's the high periodic time event that might cause lag.

JASS:
function Trig_Attack_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A001' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Attack_Func011C takes nothing returns boolean
    if ( not ( udg_Real_Pyth[1] == udg_Real_Pyth[2] ) ) then
        return false
    endif
    return true
endfunction

function Trig_Attack_Actions takes nothing returns nothing
    set udg_Point_Pyth[1] = GetUnitLoc(GetSpellAbilityUnit())
    set udg_Point_Pyth[2] = GetSpellTargetLoc()
    set udg_Real_Pyth[1] = GetLocationZ(udg_Point_Pyth[1])
    set udg_Real_Pyth[2] = GetLocationZ(udg_Point_Pyth[2])
    call CreateNUnitsAtLocFacingLocBJ( 1, 'h001', GetOwningPlayer(GetSpellAbilityUnit()), OffsetLocation(udg_Point_Pyth[1], 30.00, 30.00), udg_Point_Pyth[2] )
    call UnitApplyTimedLifeBJ( 3.00, 'BTLF', GetLastCreatedUnit() )
    call GroupAddUnitSimple( GetLastCreatedUnit(), udg_Bullets )
    call GroupAddUnitSimple( GetLastCreatedUnit(), udg_UnitGroup_Bullets )
    call SetUnitPathing( GetLastCreatedUnit(), false )
    if ( Trig_Attack_Func011C() ) then
        call SetUnitUserData( GetLastCreatedUnit(), 0 )
        call RemoveLocation( udg_Point_Pyth[1] )
        call RemoveLocation( udg_Point_Pyth[2])
    else
        set udg_Real_Pyth[1] = DistanceBetweenPoints(udg_Point_Pyth[1], udg_Point_Pyth[2])
        set udg_Real_Pyth[2] = GetLocationZ(udg_Point_Pyth[2])
        set udg_Real_Pyth[3] = ( ( Pow(udg_Real_Pyth[1], 2.00) + Pow(udg_Real_Pyth[2], 2.00) ) + 25.00 )
        set udg_Real_Pyth[3] = SquareRoot(udg_Real_Pyth[3])
        call SetUnitUserData( GetLastCreatedUnit(), ( R2I(udg_Real_Pyth[3]) / R2I(udg_Real_Pyth[1]) ) )
        call RemoveLocation( udg_Point_Pyth[1] )
        call RemoveLocation( udg_Point_Pyth[2])
    endif
endfunction

//===========================================================================
function InitTrig_Attack takes nothing returns nothing
    set gg_trg_Attack = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Attack, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Attack, Condition( function Trig_Attack_Conditions ) )
    call TriggerAddAction( gg_trg_Attack, function Trig_Attack_Actions )
endfunction

JASS:
function Trig_Attack_Periodic_Func001Func008002003001 takes nothing returns boolean
    return ( IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(udg_Bullet)) == true )
endfunction

function Trig_Attack_Periodic_Func001Func008002003002 takes nothing returns boolean
    return ( IsUnitDeadBJ(GetFilterUnit()) == false )
endfunction

function Trig_Attack_Periodic_Func001Func008002003 takes nothing returns boolean
    return GetBooleanAnd( Trig_Attack_Periodic_Func001Func008002003001(), Trig_Attack_Periodic_Func001Func008002003002() )
endfunction

function Trig_Attack_Periodic_Func001Func009A takes nothing returns nothing
    // Sniper Rifle
    set udg_WeaponDamage = 10.00
    call UnitDamageTargetBJ( udg_Bullet, GetEnumUnit(), udg_WeaponDamage, ATTACK_TYPE_MELEE, DAMAGE_TYPE_UNIVERSAL )
    call GroupRemoveUnitSimple( udg_Bullet, udg_Bullets )
    call RemoveUnit( udg_Bullet )
endfunction

function Trig_Attack_Periodic_Func001Func010C takes nothing returns boolean
    if ( not ( udg_Real_Bulletheight[2] > udg_Real_Bulletheight[3] ) ) then
        return false
    endif
    return true
endfunction

function Trig_Attack_Periodic_Func001A takes nothing returns nothing
    set udg_Point_Bullet = GetUnitLoc(GetEnumUnit())
    set udg_Bullet = GetEnumUnit()
    set udg_Real_Bulletheight[1] = GetLocationZ(udg_Point_Bullet)
    set udg_Point_Bullet = PolarProjectionBJ(udg_Point_Bullet, 20.00, GetUnitFacing(GetEnumUnit()))
    set udg_Real_Bulletheight[2] = GetLocationZ(udg_Point_Bullet)
    set udg_Real_Bulletheight[2] = ( udg_Real_Bulletheight[2] + I2R(GetUnitUserData(GetEnumUnit())) )
    set udg_Real_Bulletheight[3] = ( udg_Real_Bulletheight[1] + I2R(GetUnitUserData(GetEnumUnit())) )
    set udg_BulletHit = GetUnitsInRangeOfLocMatching(50.00, GetUnitLoc(udg_Bullet), Condition(function Trig_Attack_Periodic_Func001Func008002003))
    call ForGroupBJ( udg_BulletHit, function Trig_Attack_Periodic_Func001Func009A )
    if ( Trig_Attack_Periodic_Func001Func010C() ) then
        call UnitApplyTimedLifeBJ( 0.01, 'BTLF', GetEnumUnit() )
    else
        call SetUnitPositionLoc( GetEnumUnit(), udg_Point_Bullet )
    endif
    call UnitAddAbilityBJ( 'Amrf', GetEnumUnit() )
    call SetUnitFlyHeightBJ( GetEnumUnit(), ( ( 50.00 + I2R(GetUnitUserData(GetEnumUnit())) ) - udg_Real_Bulletheight[2] ), 0.00 )
    call UnitRemoveAbilityBJ( 'Amrf', GetEnumUnit() )
    call RemoveLocation( udg_Point_Bullet)
endfunction

function Trig_Attack_Periodic_Actions takes nothing returns nothing
    call ForGroupBJ( udg_UnitGroup_Bullets, function Trig_Attack_Periodic_Func001A )
endfunction

//===========================================================================
function InitTrig_Attack_Periodic takes nothing returns nothing
    set gg_trg_Attack_Periodic = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Attack_Periodic, 0.02 )
    call TriggerAddAction( gg_trg_Attack_Periodic, function Trig_Attack_Periodic_Actions )
endfunction
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
First trigger:

JASS:
call CreateNUnitsAtLocFacingLocBJ( 1, 'h001', GetOwningPlayer(GetSpellAbilityUnit()), OffsetLocation(udg_Point_Pyth[1], 30.00, 30.00), udg_Point_Pyth[2] )

This leaks, you have to put OffsetLocation in a variable and then destroy it.

Second trigger:

JASS:
set udg_Point_Bullet = GetUnitLoc(GetEnumUnit())  set udg_Bullet = GetEnumUnit()
set udg_Real_Bulletheight[1] = GetLocationZ(udg_Point_Bullet)
set udg_Point_Bullet = PolarProjectionBJ(udg_Point_Bullet, 20.00, GetUnitFacing(GetEnumUnit()))

This part leaks also, because you changed the location in Point_Bullet without destroying the previous one, the solution would probably be to have 2 different variables

JASS:
set udg_BulletHit = GetUnitsInRangeOfLocMatching(50.00, GetUnitLoc(udg_Bullet), Condition(function Trig_Attack_Periodic_Func001Func008002003))

This leaks, put GetUnitLoc(udg_Bullet) in a variable and then destroy it
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
A better solution is to use natives and X/Y

JASS:
local real x = GetLocationX( udg_Point_Pyth[1] ) + 30 * Cos( 30 * bj_DEGTORAD )
local real y = GetLocationY( udg_Point_Pyth[1] ) + 30 * Sin( 30 * bj_DEGTORAD )
call CreateUnit( GetOwningPlayer( GetTriggerUnit() ), 'h001', x, y, Atan2( GetLocationY( udg_Point_Pyth[2] ) - y, GetLocationX( udg_Point_Pyth[2] ) - x ) * bj_RADTODEG )

Note: you'll want to replace the locs and GetLocationX/Y, I just used them so you knew where the external values were coming from.

Second;

JASS:
local unit u = GetEnumUnit()
local location pb = GetUnitLoc(u)
local real z = GetLocationZ(pb)
local real x = GetUnitX(u) + 20 * Cos( GetUnitFacing(u) * bj_DEGTORAD )
local real y = GetUnitY(u) + 20 * Sin( GetUnitFacing(u) * bj_DEGTORAD )
call RemoveLocation(pb)
set pb = null

Note: x and y replace udg_Point_Bullet
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
You didn't give me any rep....... :(

Why???I didn't help you enough??? Huh?? Hehe just kidding :D

EDIT: Whoops, I thought that when you have 0 points (the orange square that rotates) you have 0 reps, I didn't look at my User CP, sry :)
 
Last edited:
Status
Not open for further replies.
Top