• 🏆 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!

[vJASS] Leak Check

Status
Not open for further replies.
Level 22
Joined
Feb 3, 2009
Messages
3,292
Hello, I'd like to request a leak check on the bellow spell.
It needs to be completely leak free as it's used a lot in the map.



JASS:
scope Combo initializer InitTrig_Illusion_Slash

//  SETTINGS

globals
private constant integer dummy_id = 'h00R'                             // the ID of the dummy unit
private constant integer spell_id = 'A006'                             // the ID of the spell
private constant real anim_delay = 1.00                                // the delay before the dummy dies
private constant integer red = 100                                     // the color red of the dummy
private constant integer green = 100                                   // the color green of the dummy
private constant integer blue = 100                                    // the color blue of the dummy
private constant integer alpha = 75                                    // the color transparency of the dummy
private constant integer red_c = 255                                   // the color red of the caster
private constant integer green_c = 255                                 // the color green of the caster
private constant integer blue_c = 255                                  // the color blue of the caster
private constant integer alpha_c = 100                                 // the color transparency of the caster
private constant real tag_red = 100                                    // the text tag color : red
private constant real tag_green = 10                                   // the text tag color : green
private constant real tag_blue = 10                                    // the text tag color : blue
private constant string animation = "slam"                             // the animation the dummy will play
private constant boolean attack = true                                 // is the spell a attack?
private constant boolean ranged = false                                // is the spell ranged?
private constant attacktype atk_type = ATTACK_TYPE_CHAOS               // the attack type of the dummy damage
private constant damagetype dmg_type = DAMAGE_TYPE_NORMAL              // the damage type of the dummy damage
private constant weapontype wep_type = WEAPON_TYPE_WHOKNOWS            // the weapon type of the dummy damage
private constant boolean enable_texttag = true                         // if set to true, it will show the damage dealt by the dummy
private constant string special_effect = "Abilities\\Spells\\Orc\\MirrorImage\\MirrorImageCaster.mdl"
private constant string attachment_point = "origin"                    // this is where the above special effect is placed
private real array extra_damage                                        // set the extra damage bellow in function Settings
private integer array chance                                           // set the chance bellow in function Settings
endglobals

function Settings takes nothing returns nothing
// set the chances:
set chance[1] = 20
set chance[2] = 25
set chance[3] = 30
set chance[4] = 35

// set the extra damage values
set extra_damage[1] = 25
set extra_damage[2] = 50
set extra_damage[3] = 75
set extra_damage[4] = 100
endfunction

//  END OF SETTINGS

private function Conditions takes nothing returns boolean
   return GetUnitAbilityLevel(GetAttacker(), spell_id ) >= 1
endfunction

private function Actions takes nothing returns nothing
local unit u = GetAttacker()
local unit t = GetTriggerUnit()
local unit dummy
local integer lvl = GetUnitAbilityLevel(u , spell_id)
local real dmg = extra_damage[lvl]
local real angle = GetUnitFacing(t) + 180
local player owner = GetOwningPlayer(u)
local location l = GetUnitLoc(u)
local location l2
local integer ch = GetRandomInt(1 , 100)
local texttag text
local real pos = 60.
local effect eff

if t == u then
set u = null
set t = null
set dummy = null
call RemoveLocation(l)
call RemoveLocation(l2)
set l = null
set l2 = null
return

else
// We call the chance function
call Settings()

if chance[lvl] >= ch then
set eff = AddSpecialEffectTarget(special_effect , u , attachment_point)
call SetUnitVertexColor(u, red_c , green_c, blue_c, alpha_c)
set dummy = CreateUnitAtLoc(owner, dummy_id , l , angle)
set l2 = GetUnitLoc(dummy)
call PauseUnit(dummy, true)
call SetUnitVertexColor(dummy , red , green, blue, alpha)
call SetUnitAnimation(dummy , animation)
if enable_texttag == true then
set text = CreateTextTagLocBJ( R2S(dmg)+"!" , l2, pos, 12, tag_red, tag_green, tag_blue, 0 )
call SetTextTagVelocityBJ( text, 60.00, 90 )
call SetTextTagPermanent( text, false )
call SetTextTagLifespan( text, 1)
call SetTextTagFadepoint( text, 0.1)
endif
call TriggerSleepAction(anim_delay)
call UnitDamageTarget(u, t, dmg, attack, ranged, atk_type , dmg_type , wep_type)
call RemoveUnit(dummy)
call DestroyEffect(eff)
call SetUnitVertexColor(u, 255 , 255, 255, 255)
endif

set u = null
set t = null
set dummy = null
call RemoveLocation(l)
call RemoveLocation(l2)
set l = null
set l2 = null
endif
endfunction

//===========================================================================
private function InitTrig_Illusion_Slash takes nothing returns nothing
  local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( t, Condition( function Conditions ) )
    call TriggerAddAction( t, function Actions )
endfunction
endscope
 
Last edited:
Level 18
Joined
Jan 21, 2006
Messages
2,552
It seems to be mostly leak-free. The locations are removed, and most of the handles are nulled. It doesn't look like you null your location handles though, this results in a memory leak.
 
Level 22
Joined
Feb 3, 2009
Messages
3,292
It seems to be mostly leak-free. The locations are removed, and most of the handles are nulled. It doesn't look like you null your location handles though, this results in a memory leak.

Which location didn't I destroy?

The textag wil automatically destroy after the lifespan is up


And you don't need to destroy it if you don't create it, so you can remove all your destroy textag calls.

Fixed.


Both +repped.
 
Level 15
Joined
Oct 16, 2010
Messages
941
Which location didn't I destroy?

He's saying you destroyed them both but the variable handles are still there. Just null them after you destroy them.


Honestly if you wanted to make this more efficient you should just use GetUnitX() and GetUnitY() as then you wont' have to deal with the loc API and you also won't be creating/destroying objects whenever this runs.
 
Status
Not open for further replies.
Top