Добавлен kg_toly
Я сделал способность, но она утекает. В коде не нашел утечек, но они где то есть. Помогите найти пожалуйста
карта:
видео:
globals
real rx
real ry
unit array sum
endglobals
function Trig_R_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'A006'
endfunction
function Filter_Enemy takes nothing returns boolean
local unit u = GetFilterUnit()
local integer id = GetUnitTypeId(u)
// юнит: (не юнит игрока) и (не мертв) и (не структура)
local boolean check = ( GetOwningPlayer(u) != GetOwningPlayer(sum[15]) ) and (GetUnitState(u, UNIT_STATE_LIFE) > 0) and ( IsUnitIdType(id, UNIT_TYPE_STRUCTURE) == false )
set u = null
return check
endfunction
function Filter_Vedmyak takes nothing returns boolean
local unit u = GetFilterUnit()
local integer id = GetUnitTypeId(u)
// юнит: (не мертв) и (не структура) и (не юнит игрока)
local boolean check = ( id == 'h006' ) and (GetUnitState(u, UNIT_STATE_LIFE) > 0)
set u = null
return check
endfunction
function Stun_R takes unit enemy, unit u returns nothing
local real ux = GetUnitX(u)
local real uy = GetUnitY(u)
local real x = GetUnitX(enemy)
local real y = GetUnitY(enemy)
local real a = Atan2(y-uy, x-ux)
local effect specef
// стан
local unit dummy = CreateUnit(GetOwningPlayer(u), 'u000', x, y, 0.) // Создадим дамми в координатах цели
call UnitApplyTimedLife(dummy, 'BTLF', 1) // Укажем время жизни дамми
call UnitAddAbility(dummy, 'A007')
call IssueTargetOrder(dummy, "thunderbolt", enemy)
set dummy = null
// двигаем
call SetUnitX(enemy, x + 40*Cos(a))
call SetUnitY(enemy, y + 40*Sin(a))
// визуал
call SetUnitAnimation(u, "spell")
set specef = AddSpecialEffect("Abilities\\Spells\\Other\\Incinerate\\IncinerateBuff.mdl", ux, uy)
call DestroyEffect(specef)
set specef = null
endfunction
function Vedmyak takes nothing returns nothing
local unit u = GetEnumUnit()
local unit enemy
local group g = CreateGroup()
local real ux = GetUnitX(u) // позиция юнита
local real uy = GetUnitY(u)
local real x // позиция врага
local real y
local real a
call GroupEnumUnitsInRange(g, ux, uy, 100, Condition(function Filter_Enemy))
loop
set enemy = FirstOfGroup(g)
exitwhen enemy == null
call Stun_R(enemy, u)
call GroupRemoveUnit(g, enemy)
endloop
call DestroyGroup(g)
set g = null
set u = null
set enemy = null
endfunction
function NoEscape takes nothing returns nothing
local timer t = GetExpiredTimer()
local group g = CreateGroup()
local unit u
call GroupEnumUnitsInRange(g, rx, ry, 450, Condition(function Filter_Vedmyak))
set u = FirstOfGroup(g)
if u == null then
call PauseTimer(t)
call DestroyTimer(t)
else
call ForGroup(g, function Vedmyak)
endif
call DestroyGroup(g)
set g = null
set u = null
set t = null
endfunction
function CreateArena takes player owner returns nothing
local integer i = 0
local real a
local real ux
local real uy
loop
exitwhen i >= 15 // Создаёт 8 стен, образуя круг
set a = i * 24 * bj_DEGTORAD
set ux = rx + 400 * Cos(a)
set uy = ry + 400 * Sin(a)
set a = Atan2(ry-uy, rx-ux) * bj_RADTODEG
set sum[i+14] = CreateUnit(owner, 'h006', ux, uy, a)
call SetUnitAnimation(sum[i+14], "stand defend")
call UnitApplyTimedLife(sum[i+14], 'BFig', 3) // Исчезает через 10 сек sum i +14
set i = i + 1
endloop
endfunction
function Trig_R_Actions takes nothing returns nothing
local timer t = CreateTimer()
local unit caster = GetTriggerUnit()
local player owner = GetOwningPlayer(caster)
set rx = GetSpellTargetX()
set ry = GetSpellTargetY()
call CreateArena(owner)
call TimerStart(t, 0.1, true, function NoEscape)
set t = null
set caster = null
set owner = null
endfunction
function InitTrig_R takes nothing returns nothing
local trigger trg = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(trg, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(trg, Condition(function Trig_R_Conditions))
call TriggerAddAction(trg, function Trig_R_Actions)
endfunction
Принятый ответ
Начни с того, чтоб юзать нормальный счётчик хэндлов.
И зачем ты плодишь переменные еффектов?
set specef = AddSpecialEffect("Abilities\\Spells\\Other\\Incinerate\\IncinerateBuff.mdl", ux, uy)
call DestroyEffect(specef)
set specef = null
Можно же проще:
call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Other\\Incinerate\\IncinerateBuff.mdl", ux, uy))
`
ОЖИДАНИЕ РЕКЛАМЫ...
Чтобы оставить комментарий, пожалуйста, войдите на сайт.
Это не удаление даммика, это обнуление переменной, нужно RemoveUnit(dummy)
Ред. LastUchiha
Это же целочисленная?
Так что попробуй убрать эффекты и утечки посчитать.
Ред. kg_toly
nazarpunk, но я же использовал сразу два счетчика, чтобы наверняка, или они оба неправильно работают и на самом деле нет утечек памяти? про эффекты не знал, отныне буду так делать.
LastUchiha, я на всякий случай обнуляю все хендлы, чтообы наверняка не было утечек.
https://xgm.guru/p/wc3/wfetool
Ред. kg_toly
Ред. SoulRazor
Более оптимизированная версия, попробуй проверить ее на уточки.
извиняюсь, оказывается этот вопрос можно было бы избежать если бы не моя ошибка