| 01-12-2009, 03:33 AM | #1 |
Bleh, I seem to have coded my effect system poorly. It's leaking effects and I can't figure out why, could someone point it out? I'm sure it's a simple issue I'm not seeing. JASS:struct ATTACHEDSFX effect e integer dur endstruct globals ATTACHEDSFX array ATTACHED_SFX integer SFX_COUNTER = 0 timer SFX_TIMER = CreateTimer() endglobals function AttachedSFXHandler takes nothing returns nothing local ATTACHEDSFX fx local integer I = SFX_COUNTER - 1 loop set fx = ATTACHED_SFX[i] set ATTACHED_SFX[i].dur = ATTACHED_SFX[i].dur - 1 if(fx.dur == 0)then call DestroyEffect(fx.e) call fx.destroy() set ATTACHED_SFX[i] = ATTACHED_SFX[SFX_COUNTER] set SFX_COUNTER = SFX_COUNTER - 1 endif exitwhen(I == 0) set I = I - 1 endloop if(SFX_COUNTER == 0)then call PauseTimer(SFX_TIMER) endif endfunction function AttachTemporarySFX takes unit u, integer dur, string model, string where returns nothing local ATTACHEDSFX asfx = ATTACHEDSFX.create() set asfx.e = AddSpecialEffectTarget(model, u, where) set asfx.dur = dur set ATTACHED_SFX[SFX_COUNTER] = asfx if(SFX_COUNTER == 0)then call TimerStart(SFX_TIMER, .33, true, function AttachedSFXHandler) endif set SFX_COUNTER = SFX_COUNTER + 1 endfunction It never leaks the first instances, after that it seems to be fair game. |
| 01-12-2009, 04:07 AM | #2 |
set ATTACHED_SFX[i] = ATTACHED_SFX[SFX_COUNTER] change to set ATTACHED_SFX[i] = ATTACHED_SFX[SFX_COUNTER - 1]
SFX_COUNTER is always 1 more than the last index (since you set and then increment). You can also decrement and move instead of the subtraction. |
| 01-13-2009, 02:55 AM | #3 |
LOL I almost fell out of my chair laughing. What a stupid mistake that was >.<. Thank you ammorth, it works great now :). |
| 01-13-2009, 03:46 AM | #4 |
I used to do it all the time too, so I know to look for it :P |
