HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Do I have a mem leak?

09-10-2004, 06:21 PM#1
curi
I've got my repeating special effects working, but I'm not sure if I did all the memory leak stuff correctly. Primitives don't need to be set to null, right? I appreciate any help.

Code:
// functions to create and cleanup special effects in patterns, with the option of having them repeated

// MINIMUM WAIT IS .25 SECONDS
// But feel free to call the function many times at once to make up for that

// 3 examples: (set udg_loc to something to use)

//call sfxr("random", 300, 60, .05, udg_loc, "Objects\\Spawnmodels\\Human\\FragmentationShards\\FragBoomSpawn.mdl")

//call sfxr("random", 400, 15, .2, udg_loc, "Abilities\\Spells\\Demon\\ReviveDemon\\ReviveDemon.mdx")

//call sfxp("one", 400, udg_loc, "Abilities\\Spells\\Demon\\ReviveDemon\\ReviveDemon.mdx")

function sfx_child takes nothing returns nothing
    local effect e = bj_lastCreatedEffect
    call PolledWait( 120 )
    call DestroyEffect( e )
endfunction

function sfx takes location mytarget, string sfxpath returns nothing

	local trigger t = CreateTrigger()

    set bj_lastCreatedEffect = AddSpecialEffectLoc(sfxpath, mytarget)
	call TriggerAddAction( t, function sfx_child )
	call TriggerExecute( t )
	call DestroyTrigger( t )
	set t = null

endfunction

function sfxhelper takes real x, real y, string sfxpath returns nothing

	local trigger t = CreateTrigger()

    set bj_lastCreatedEffect = AddSpecialEffect(sfxpath, x, y)
	call TriggerAddAction( t, function sfx_child )
	call TriggerExecute( t )
	call DestroyTrigger( t )
	set t = null

endfunction


function sfxp takes string pattern, real distance, location mytarget, string sfxpath returns nothing

local trigger t = CreateTrigger()
local real ndistance = distance * -1
local real lx = GetLocationX(mytarget)
local real ly = GetLocationY(mytarget)
local integer p = GetRandomInt(1,5)
local real angle = GetRandomReal(0, 360)

if( pattern == "random" ) then
// pick a random pattern to do

	if( p == 1 ) then
		set pattern = "one"
	elseif( p == 2 ) then
		set pattern = "diamond"
	elseif( p == 3 ) then
		set pattern = "square"
	elseif( p == 4 ) then
		set pattern = "randomsquare"
	elseif( p == 5 ) then
		set pattern = "randomcircle"
	endif

endif

if( pattern == "one" ) then
// make sfx on mytarget
    call sfxhelper( lx, ly, sfxpath )

    	
elseif( pattern =="diamond" ) then
// make sfx north, south, east, west of mytarget
	call sfxhelper( lx, ly +distance, sfxpath )
	call sfxhelper( lx, ly+ndistance, sfxpath )
	call sfxhelper( lx +distance, ly, sfxpath )
	call sfxhelper( lx+ndistance, ly, sfxpath )
	

elseif( pattern == "square" ) then
// make sfx ne, se, nw, sw of mytarget

	call sfxhelper( lx+distance, ly +distance, sfxpath )
	call sfxhelper( lx+distance, ly+ndistance, sfxpath )
	call sfxhelper( lx +ndistance, ly+ndistance, sfxpath )
	call sfxhelper( lx+ndistance, ly+distance, sfxpath )


elseif( pattern == "randomsquare" ) then
// make sfx randomly in square

	call sfxhelper( lx + GetRandomReal(ndistance, distance), ly + GetRandomReal(ndistance, distance), sfxpath )
	
elseif( pattern == "randomcircle" ) then
// make sfx randomly in circle

	call sfxhelper( lx + distance * Cos(angle * bj_DEGTORAD), ly + distance * Sin(angle * bj_DEGTORAD), sfxpath )

endif

set t = null
endfunction




function sfxr_child takes nothing returns nothing
	local string pattern = bj_changeLevelMapName
	local real distance = bj_randomSubGroupChance
	local integer times = bj_randomSubGroupTotal
	local real delay = bj_enumDestructableRadius
	local location mytarget = bj_enumDestructableCenter
	local string sfxpath = bj_lastPlayedMusic
	
	loop
		exitwhen (times <= 0)
		set times = times - 1
		call sfxp ( pattern, distance, mytarget, sfxpath )
		call PolledWait( delay )
	
	endloop
	
	set pattern = null
	set sfxpath = null
	set mytarget = null
	
endfunction




function sfxr takes string pattern, real distance, integer times, real delay, location mytarget, string sfxpath returns nothing
local trigger t = CreateTrigger()
local string bj1 = bj_changeLevelMapName
local real bj2 = bj_randomSubGroupChance
local integer bj3 = bj_randomSubGroupTotal
local real bj4 = bj_enumDestructableRadius
local location bj5 = bj_enumDestructableCenter
local string bj6 = bj_lastPlayedMusic

set bj_changeLevelMapName = pattern
set bj_randomSubGroupChance = distance
set bj_randomSubGroupTotal = times
set bj_enumDestructableRadius = delay
set bj_enumDestructableCenter = mytarget
set bj_lastPlayedMusic = sfxpath

call TriggerAddAction( t, function sfxr_child )
call TriggerExecute( t )
call DestroyTrigger( t )

set bj_changeLevelMapName = bj1
set bj_randomSubGroupChance = bj2
set bj_randomSubGroupTotal = bj3
set bj_enumDestructableRadius = bj4
set bj_enumDestructableCenter = bj5
set bj_lastPlayedMusic = bj6
set bj1 = null
set bj5 = null
set bj6 = null

set t = null
endfunction
09-11-2004, 01:30 AM#2
PitzerMike
You did all your best to prevent leaks.

Looks okay to me.
09-15-2004, 04:14 PM#3
Cacodemon
You may also use one bug (?) to destroy NON-PERIODIC special effects:

Code:
call DestroyEffect(AddSpecialEffect...(....))

No need to wait or create new threads - this will surely work :)
09-15-2004, 04:32 PM#4
curi
if it's destroyed right away, will it be visible ingame at all? that makes no sense to me.

i know if you use something that sticks around permanently, it will disappear when destroyed.
09-17-2004, 12:39 AM#5
fugly
special effects have to show their animation atleast once, once it is done showing its animation once it'll then disapear.
also you could just use TriggerSleepAction()
09-17-2004, 10:12 AM#6
Cubasis
Code:
also you could just use TriggerSleepAction()

egh...

No he could not. That's what he was using before he run into the problem of stalling the calling function. He'd need to create a special thread for it, and that's what he's allready doing. (see "function sfx")