• 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] Any more Leaks in it?

Status
Not open for further replies.
Level 16
Joined
Feb 22, 2006
Messages
960
so here is my castbar system i made, actually i'm learning to handle with gamecaches and the handlevar system, so i asked my self if i found all leaks

JASS:
function castbar takes nothing returns nothing
  local timer t = GetExpiredTimer()
  local unit u = GetHandleUnit(t,"caster")
  local integer duration = GetHandleInt(t,"duration")
  local location loc
  local real zeit = GetHandleReal(t,"zeit")
  local texttag textt = GetHandleTexttag(t,"textt")
  local texttag textbarone = GetHandleTexttag(t,"textbarone")
  local texttag textbartwo = GetHandleTexttag(t,"textbartwo")
  local string text = "|"
  local string textbartext = GetHandleString(t,"textbartext")
    set zeit = zeit - interval()   
    set textbartext = textbartext + text
    set loc = GetUnitLoc(u)
    call SetTextTagPosBJ(textt,loc,200.00)
    call SetTextTagPosBJ(textbarone,loc,200.00)
    call SetTextTagPosBJ(textbartwo,loc,200.00)
    call SetTextTagTextBJ(textbartwo,textbartext,10)
    call SetTextTagTextBJ(textt,R2S(zeit),8)
    call RemoveLocation(loc)
    if (duration <= 1) then
        call FlushHandleLocals(t)
        call DestroyTextTag(textt)        
        call DestroyTextTag(textbarone)
        call DestroyTextTag(textbartwo)
        call DestroyTimer(t)        
        set loc = null
        set u = null
        set textt = null
        set textbarone = null
        set textbartwo = null
        set t = null
        return
    endif
  set loc = null
  set u = null
  call SetHandleReal(t,"zeit",zeit)
  call SetHandleInt(t,"duration",duration-1)
  call SetHandleString(t,"textbartext",textbartext)  
endfunction

function castbar_action takes real time,unit u returns nothing
  local timer t = CreateTimer()
  local integer i = 200
  local location loc = GetUnitLoc(u)
  local string newtext = ""
  local string text = "|"
  local string textbar = ""
  local texttag tg
  local texttag tt
  local texttag tb
  local integer loopint = 0 
    loop
        exitwhen loopint >= R2I(time/interval())
        set newtext = newtext + text
        set loopint = loopint + 1
    endloop
    set tt = CreateTextTagLocTwo(newtext,loc,200.00,10,10,10,10,0)
    set tb = CreateTextTagLocTwo(textbar,loc,200.00,10,100,0,0,0)
    set tg = CreateTextTagLocTwo(R2S(time),loc,200.00,8,100,100,100,0) 
    call SetHandleInt(t,"duration",R2I(time/interval()))
    call SetHandleReal(t,"zeit",time)
    call SetHandleString(t,"textbartext",textbar)
    call SetHandleHandle(t,"caster",u)
    call SetHandleHandle(t,"textt",tg)
    call SetHandleHandle(t,"textbarone",tt)
    call SetHandleHandle(t,"textbartwo",tb)
    call TimerStart(t,interval(),true,function castbar)
  call RemoveLocation(loc)
  set loc = null  
endfunction
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
You got very few leaks left.
In the function "castbar_action" you forgot to null the timer and the texttags.
In the function "castbar" you should pause the timer before you destroy it and the nulling of "loc" and "u" can be put before this line: if (duration <= 1) then this way you reduce the length of your code by 2 lines ^^.
 
Status
Not open for further replies.
Top