Leaks

Builder Bob

Live free or don't
Reaction score
249
SFilip, could you please help me understand what really happens to the boolexpr in the following trigger?
I'm assuming local boolexpr f = Condition(function KillSelected) creates a handle and makes f point to it.
I'm also assuming DestroyBoolExpr(f) destroys the handle f is pointing to, and not the actual condition.
Why else, would this trigger work?
I'm pretty sure I'm wrong on something here, I just don't know what.


The trigger kills every selected unit on esc.
JASS:
function KillSelected takes nothing returns boolean
	call KillUnit(GetFilterUnit())
	return false
endfunction

function OnEsc takes nothing returns boolean
	local group g = CreateGroup()
	local boolexpr f = Condition(function KillSelected)
	call GroupEnumUnitsSelected(g, GetTriggerPlayer(), f)
	call DestroyBoolExpr(f)
	call DestroyGroup(g)
	set f = null
	set g = null
	return false
endfunction

//===========================================================================
function InitTrig_SelectedOnEsc takes nothing returns nothing
	local trigger trigEsc = CreateTrigger()
	local integer i = 0
	loop
		call TriggerRegisterPlayerEvent(trigEsc, Player(i), EVENT_PLAYER_END_CINEMATIC)
		set i = i + 1
		exitwhen(i == 12)
	endloop
	call TriggerAddCondition(trigEsc, Condition(function OnEsc))
	set trigEsc = null
endfunction



kallieblakie, I'll look through your code and see what I can find

Edit: I can't compile this for obvious reasons, but I think it is leakfree now.

I took the liberty to remove some locations in favor of coordinates. It's easier to work with as reals and integers can't leak. You can change the rest if you want to. Variables usually only have to be destroyed and nulled at the same indentation level that they are created. This is by no means a rule though.

JASS:
function Arrow_Filter takes nothing returns boolean
	return IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) != true and GetWidgetLife(GetFilterUnit()) > 0.405 
endfunction

function Trig_Arrow_Elunes_Arrow_Conditions takes nothing returns boolean
	return GetSpellAbilityId() == 'AOsh'
endfunction

function DPP takes location locA, location locB returns real
	local real dx = GetLocationX(locB) - GetLocationX(locA)
	local real dy = GetLocationY(locB) - GetLocationY(locA)
	return SquareRoot(dx * dx + dy * dy)
endfunction

function Arrow_Move takes nothing returns nothing
	local timer Loop = GetExpiredTimer()
	local unit arrow = GetHandleUnit(Loop, "arrow")
	local unit caster = GetHandleUnit(Loop, "caster")
	local real angle = GetHandleReal(Loop, "angle")
	local integer Range = GetHandleInt(Loop, "Range")
	local integer Radius = GetHandleInt(Loop, "Radius")
	local real Speed = GetHandleReal(Loop, "Speed")
	local integer PlayerNo = GetHandleInt(Loop, "PlayerNo")
	local real distanceCurrent = GetHandleReal(Loop, "distanceCurrent")
	local location C
	local location Next
	local boolexpr b
	local real x 
	local real y
	local group g
	local unit p
	local unit dummy
	local integer Number
	local location locA
	local location locB
	if (R2I(distanceCurrent) <= Range) then
		set distanceCurrent = distanceCurrent + Speed
		call SetHandleReal (Loop, "distanceCurrent", distanceCurrent)
		set x = GetUnitX(arrow) + Speed * Cos(angle * bj_DEGTORAD)
		set y = GetUnitY(arrow) + Speed * Sin(angle * bj_DEGTORAD)
		call SetUnitPosition(arrow, x, y)
		set g = CreateGroup()
		set b = Condition(function Arrow_Filter)
		call GroupEnumUnitsInRangeCounted(g, x, y, I2R(Radius), b, 1)
		call DestroyBoolExpr(b)
		set b = null
		set p = FirstOfGroup(g)
		call DestroyGroup(g)
		set g = null
		if p != null then
			if ( ( UnitHasBuffBJ(p, 'BPSE') == true ) ) then
				call UnitDamageTarget(caster, p, 100000, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
				call RemoveUnit(arrow)
				
				//---I think you should flush and destroy the timer here as well
				
				call FlushHandleLocals(Loop)
				call PauseTimer(Loop)
				call DestroyTimer(Loop)
			elseif ( (IsUnitEnemy(p, GetOwningPlayer(caster)) == true)) then
				call UnitDamageTarget(caster, p, udg_Damage[PlayerNo], false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)

				set dummy = CreateUnitAtLoc(GetOwningPlayer(caster), 'hfoo', Next, 0.00)
				call UnitAddAbility(dummy, 'ANsb')
				call SetUnitAbilityLevel(dummy, 'ANsb', udg_Stun[PlayerNo])
				call IssueTargetOrder(dummy, "thunderbolt", p)
				call UnitApplyTimedLife(dummy, 'BTLF', 2.00)

				set locA = GetUnitLoc(caster)
				set locB = GetUnitLoc(arrow)
				call UnitDamageTarget(caster, p, (( I2R(udg_I_PrecisionLevel[PlayerNo]) * ( 0.06 * DPP(locA,locB)))+( ( 35000.00 * ( 0.40 * I2R(udg_I_bladeLevel[PlayerNo]) ) ) / DPP(locA,locB))),false,true, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_METAL_HEAVY_BASH )
				call RemoveLocation (locA)
				call RemoveLocation (locB)
				set locA = null
				set locB = null
				call RemoveUnit(arrow)
				call FlushHandleLocals(Loop)
				call PauseTimer(Loop)
				call DestroyTimer(Loop)
			endif
			set p = null
		endif
	elseif (R2I(distanceCurrent) > Range) then
		call KillUnit(arrow)
		call RemoveUnit(arrow)
		call FlushHandleLocals(Loop)
		call PauseTimer(Loop) 
		call DestroyTimer(Loop) 
	endif
	set arrow = null
	set caster = null
	set Loop = null
endfunction

function Trig_Arrow_Elunes_Arrow_Actions takes nothing returns nothing
	local timer Loop = CreateTimer()
	local unit caster = GetSpellAbilityUnit()
	local location casterPosition = GetUnitLoc(caster)
	local location targetPosition = GetSpellTargetLoc()
	local integer PlayerNo = GetConvertedPlayerId(GetOwningPlayer(GetSpellAbilityUnit())) //I won't start messing with playerIds, but I like Player() and GetPlayerId() functions better
	local integer radius = udg_Radius[PlayerNo]
	local real angle = AngleBetweenPoints(casterPosition, targetPosition)
	local real x = GetLocationX(casterPosition) + (radius+2)*Cos(angle*bj_DEGTORAD)
	local real y = GetLocationY(casterPosition) + (radius+2)*Sin(angle*bj_DEGTORAD)
	local real Scale = ( 100.00 * ( I2R(radius) / 80.00 ) )
	
	local integer Range = udg_Range[PlayerNo]
	local real Speed = udg_Speed[PlayerNo]
	local unit arrow = CreateUnit(ConvertedPlayer(PlayerNo), 'hpea', x, y, angle)
	call SetUnitScalePercent( arrow, Scale, Scale, Scale )
	call SetUnitPathing( arrow, false )
	call RemoveLocation(casterPosition)
	call RemoveLocation(targetPosition)
	
	call SetHandleHandle(Loop, "arrow", arrow)
	call SetHandleHandle(Loop, "caster", caster)
	call SetHandleReal(Loop,"angle",angle)
	call SetHandleInt(Loop, "Range", Range)
	call SetHandleReal(Loop, "Speed", Speed)
	call SetHandleInt(Loop, "Radius", radius)
	call SetHandleInt(Loop, "PlayerNo", PlayerNo)
	call TimerStart(Loop, 0.03, true, function Arrow_Move)
	set Loop = null
	set caster = null
	set casterPosition = null
	set targetPosition = null
	set arrow = null
endfunction

//===========================================================================
function InitTrig_Arrow_Elunes_Arrow takes nothing returns nothing
	set gg_trg_Arrow_Elunes_Arrow = CreateTrigger()
	call TriggerRegisterAnyUnitEventBJ( gg_trg_Arrow_Elunes_Arrow, EVENT_PLAYER_UNIT_SPELL_EFFECT )
	call TriggerAddCondition( gg_trg_Arrow_Elunes_Arrow, Condition( function Trig_Arrow_Elunes_Arrow_Conditions ) )
	call TriggerAddAction( gg_trg_Arrow_Elunes_Arrow, function Trig_Arrow_Elunes_Arrow_Actions )
endfunction
 

Builder Bob

Live free or don't
Reaction score
249
Anyway, the trigger doesn't work! it doesn't properly destroy the loop when it hits a unit. ARGGHS

Hmm... that's weird. I must have done a mistake. Can you tell me more about what happens?

Does the arrow move as it should and as far as it should?
Do units get damaged when the arrow goes through them?
Does it hit some times but not always?
etc.

I need more info to correct the mistake without being able to test myself.


Here is how you can pinpoint the bug yourself:
Place small debug messages after every if, elseif and else so you know what code is being run and what's not.

Then find out why the if/elseif argument isn't returning true by checking what the varibales in that argument is all the way from the beginning of the trigger and up to the if/elseif in question. When you find out where the value is wrong, you can usually know why and correct it.


Addition - Skip this if you want:

Put this function in your header. If you don't know what that is, look for mapname.w3x above all your triggers.
JASS:
function DebugUnitTag takes string s, unit u returns nothing
	local texttag tag = CreateTextTag()
	local integer width = StringLength(s)
	call SetTextTagText(tag, s, 0.023)
	call SetTextTagPos(tag, GetUnitX(u) - width * 10, GetUnitY(u), 0.)
	call SetTextTagColor(tag, 255, 50, 50, 255)
	call SetTextTagPermanent(tag, false)
	call SetTextTagLifespan(tag, 3.)
	call SetTextTagFadepoint(tag, 1.5)
	call SetTextTagVelocity(tag, 0., .071)
	set tag = null
endfunction


Now you can write DebugUnitTag("something or whatever", p) and you will get a floating text saying "something or whatever" over the unit p. It's leakless and I find it can help pinpoint bugs much easier.

Good hunting!
 

kallieblakie

New Member
Reaction score
5
Hmm... that's weird. I must have done a mistake. Can you tell me more about what happens?

Does the arrow move as it should and as far as it should?
Do units get damaged when the arrow goes through them?
Does it hit some times but not always?
etc.

I need more info to correct the mistake without being able to test myself.


Here is how you can pinpoint the bug yourself:
Place small debug messages after every if, elseif and else so you know what code is being run and what's not.

Then find out why the if/elseif argument isn't returning true by checking what the varibales in that argument is all the way from the beginning of the trigger and up to the if/elseif in question. When you find out where the value is wrong, you can usually know why and correct it.
I've already corrected the mistake. The script you made allows the arrow to does extra few hits to the enemy before it disappears. say, supposingly it should deal 100 damage, your script allows the arrow to "poke" the enemy 4-5 times, dealing 500 damage instead.


JASS:
			elseif ( (IsUnitEnemy(p, GetOwningPlayer(caster)) == true)) then
				call UnitDamageTarget(caster, p, udg_Damage[PlayerNo], false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)

				set dummy = CreateUnitAtLoc(GetOwningPlayer(caster), 'hfoo', Next, 0.00)
				call UnitAddAbility(dummy, 'ANsb')
				call SetUnitAbilityLevel(dummy, 'ANsb', udg_Stun[PlayerNo])
				call IssueTargetOrder(dummy, "thunderbolt", p)
				call UnitApplyTimedLife(dummy, 'BTLF', 2.00)

				set locA = GetUnitLoc(caster)
				set locB = GetUnitLoc(arrow)
				call UnitDamageTarget(caster, p, (( I2R(udg_I_PrecisionLevel[PlayerNo]) * ( 0.06 * DPP(locA,locB)))+( ( 35000.00 * ( 0.40 * I2R(udg_I_bladeLevel[PlayerNo]) ) ) / DPP(locA,locB))),false,true, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_METAL_HEAVY_BASH )
				call RemoveLocation (locA)
				call RemoveLocation (locB)
				set locA = null
				set locB = null
				call RemoveUnit(arrow)
				call FlushHandleLocals(Loop)
				call PauseTimer(Loop)
				call DestroyTimer(Loop)


the
JASS:
				call RemoveUnit(arrow)

cannot be placed so low in the trigger. I shifted it up and it works perfectly fine.

Thanks for your help!

my map is now available at www.geocities.com/kallieblakie
 

Builder Bob

Live free or don't
Reaction score
249
Ah, very nice that you fixed it. Does it leak anymore?

I have an ability much like this, and I remove the arrow at the very end of the code. Guess yours does something I don't really understand or something.

By the way... Now that I look over the code I posted for you again, I see some mistakes. I removed the Next location from most of the code and replaced it with x and y, but I didn't remember to remove it where the dummy is created.

In any case, glad to be of some help.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top