Double free of type: Weird error

Matemeo

New Member
Reaction score
20
I'm making a spell that shoots out orbs, and as it passes near enemies it'll randomly zap one till it gets to the end of its path. Heres the spell

JASS:

scope Orbs

        globals
                constant integer ORBS_AID = 'A005'
                constant integer ORBS_UID ='n000'
                constant integer DUMMY_UID = 'hmpr'
                constant integer CL_AID = 'A006'
        endglobals
        
        struct Orbs
                unit caster
                unit Orb
                real x
                real y
        endstruct
        
        private function o_check takes nothing returns boolean
                return IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(GetTriggerUnit())) and GetUnitState(GetFilterUnit(),UNIT_STATE_LIFE) > .465
        endfunction
        
        private function t_callback takes nothing returns nothing
                local timer t = GetExpiredTimer()
                local unit temp
                local group g = CreateGroup()
                local Orbs o = GetTimerStructA(t)
                local real x = GetUnitX(<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite12" alt="o_O" title="Er... what?    o_O" loading="lazy" data-shortname="o_O" />rb)
                local real y = GetUnitY(<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite12" alt="o_O" title="Er... what?    o_O" loading="lazy" data-shortname="o_O" />rb)
                local unit dummy = CreateUnit(GetOwningPlayer(GetTriggerUnit()),DUMMY_UID,x,y,270.0)
                
                call UnitAddAbility(dummy,CL_AID)
                //Check to see if orb is at the end of its path
                if x &lt; o.x + 100 and x &gt; o.x - 100 and y &gt; o.y - 100 and y &lt; o.y + 100 then
                        call PauseTimer(t)
                        call ClearTimerStructA(t)
                        call DestroyTimer(t)
                        set t =null
                else
                        call GroupEnumUnitsInRange(g,x,y,300.0,Condition(function o_check))
                        set temp = GroupPickRandomUnit(g)
                        call IssueTargetOrder(dummy,&quot;chainlightning&quot;,temp)
                        call RemoveUnit(dummy)
                endif
                set t = null
                call DestroyGroup(g)
                set g =null
                set temp =null
                call o.destroy()
                set dummy = null
        endfunction
        
        private function Conditions takes nothing returns boolean
                return GetSpellAbilityId() == ORBS_AID
        endfunction

        private function Actions takes nothing returns nothing
                local Orbs o = Orbs.create()
                local timer t = CreateTimer()
                local location l = GetSpellTargetLoc()
                local unit Orb 
                set o.caster = GetTriggerUnit()
                set o.x = GetLocationX(l)
                set o.y = GetLocationY(l)
                set Orb = CreateUnit(GetOwningPlayer(o.caster),ORBS_UID,GetUnitX(o.caster),GetUnitY(o.caster),270.0)
                set <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite12" alt="o_O" title="Er... what?    o_O" loading="lazy" data-shortname="o_O" />rb = Orb
                call IssuePointOrder(Orb,&quot;move&quot;,o.x,o.y)
                call SetTimerStructA(t,o)
                call o.destroy()
                call TimerStart(t,.25,true,function t_callback)
                
                set t = null
                call RemoveLocation(l)
                set l = null
                set Orb = null
                
        endfunction

        //===========================================================================
        public function InitTrig takes nothing returns nothing
            local trigger t = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
            call TriggerAddCondition(t, Condition( function Conditions ) )
            call TriggerAddAction(t, function Actions )
        endfunction
endscope


When I test map to test the spell every .25 seconds I get a Double Free of Type: Orbs, error spamming on my screen. Can anyone shed some light on what this is? :cool: Any help is appreciated, thanks in advance.
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
JASS:
scope Orbs

        globals
                constant integer ORBS_AID = &#039;A005&#039;
                constant integer ORBS_UID =&#039;n000&#039;
                constant integer DUMMY_UID = &#039;hmpr&#039;
                constant integer CL_AID = &#039;A006&#039;
        endglobals
        
        struct Orbs
                unit caster
                unit Orb
                real x
                real y
        endstruct
        
        private function o_check takes nothing returns boolean
                return IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(GetTriggerUnit())) and GetUnitState(GetFilterUnit(),UNIT_STATE_LIFE) &gt; .465
        endfunction
        
        private function t_callback takes nothing returns nothing
                local timer t = GetExpiredTimer()
                local unit temp
                local group g = CreateGroup()
                local Orbs o = GetTimerStructA(t)
                local real x = GetUnitX(<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite12" alt="o_O" title="Er... what?    o_O" loading="lazy" data-shortname="o_O" />rb)
                local real y = GetUnitY(<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite12" alt="o_O" title="Er... what?    o_O" loading="lazy" data-shortname="o_O" />rb)
                local unit dummy = CreateUnit(GetOwningPlayer(GetTriggerUnit()),DUMMY_UID,x,y,270.0)
                
                call UnitAddAbility(dummy,CL_AID)
                //Check to see if orb is at the end of its path
                if x &lt; o.x + 100 and x &gt; o.x - 100 and y &gt; o.y - 100 and y &lt; o.y + 100 then
                        call PauseTimer(t)
                        //
                        call o.destroy()
                        call ClearTimerStructA(t)
                        call DestroyTimer(t)
                        set t =null
                else
                        call GroupEnumUnitsInRange(g,x,y,300.0,Condition(function o_check))
                        set temp = GroupPickRandomUnit(g)
                        call IssueTargetOrder(dummy,&quot;chainlightning&quot;,temp)
                        call RemoveUnit(dummy)
                endif
                set t = null
                call DestroyGroup(g)
                set g =null
                set temp =null
                //call o.destroy()
                set dummy = null
        endfunction
        
        private function Conditions takes nothing returns boolean
                return GetSpellAbilityId() == ORBS_AID
        endfunction

        private function Actions takes nothing returns nothing
                local Orbs o = Orbs.create()
                local timer t = CreateTimer()
                local location l = GetSpellTargetLoc()
                local unit Orb 
                set o.caster = GetTriggerUnit()
                set o.x = GetLocationX(l)
                set o.y = GetLocationY(l)
                set Orb = CreateUnit(GetOwningPlayer(o.caster),ORBS_UID,GetUnitX(o.caster),GetUnitY(o.caster),270.0)
                set <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite12" alt="o_O" title="Er... what?    o_O" loading="lazy" data-shortname="o_O" />rb = Orb
                call IssuePointOrder(Orb,&quot;move&quot;,o.x,o.y)
                call SetTimerStructA(t,o)
                //call o.destroy()
                call TimerStart(t,.25,true,function t_callback)
                
                set t = null
                call RemoveLocation(l)
                set l = null
                set Orb = null
                
        endfunction

        //===========================================================================
        public function InitTrig takes nothing returns nothing
            local trigger t = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
            call TriggerAddCondition(t, Condition( function Conditions ) )
            call TriggerAddAction(t, function Actions )
        endfunction
endscope

I made comments at the changes. If you create one struct, then you should destroy one struct, not "one struct per time the timer expires". Structs are no different (well...) from timers, units or anything else you can destroy.
 

Matemeo

New Member
Reaction score
20
Oh, alright, no more errors now :D
however, it doesn't work as intended, doesn't ever target and use chainlightning on any unit.
It's almost a game, spot the stupid obvious error :p
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
More changes ^^

JASS:
        private function t_callback takes nothing returns nothing
                local timer t = GetExpiredTimer()
                local unit temp
                local group g = CreateGroup()
                local Orbs o = GetTimerStructA(t)
                local real x = GetUnitX(<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite12" alt="o_O" title="Er... what?    o_O" loading="lazy" data-shortname="o_O" />rb)
                local real y = GetUnitY(<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite12" alt="o_O" title="Er... what?    o_O" loading="lazy" data-shortname="o_O" />rb)
                local unit dummy
                
                call UnitAddAbility(dummy,CL_AID)
                //Check to see if orb is at the end of its path
                if x &lt; o.x + 100 and x &gt; o.x - 100 and y &gt; o.y - 100 and y &lt; o.y + 100 then
                        call PauseTimer(t)
                        //
                        call o.destroy()
                        call ClearTimerStructA(t)
                        call DestroyTimer(t)
                        set t =null
                else
                        dummy = CreateUnit(GetOwningPlayer(GetTriggerUnit()),DUMMY_UID,x,y,270.0)
                        call GroupEnumUnitsInRange(g,x,y,300.0,Condition(function o_check))
                        set temp = GroupPickRandomUnit(g)
                        call IssueTargetOrder(dummy,&quot;chainlightning&quot;,temp)
                        call UnitApplyTimedLife(dummy, &#039;BTLF&#039;, 5)
                endif
                set t = null
                call DestroyGroup(g)
                set g =null
                set temp =null
                //call o.destroy()
                set dummy = null
        endfunction
 

Matemeo

New Member
Reaction score
20
Even with the changes, still does not work, any clue why? The orbs just go flying by...no zapping :mad:
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
any clue why?
Yes :banghead:

Well, new changes ^^

JASS:
scope Orbs

        globals
                constant integer ORBS_AID = &#039;A005&#039;
                constant integer ORBS_UID =&#039;n000&#039;
                constant integer DUMMY_UID = &#039;hmpr&#039;
                constant integer CL_AID = &#039;A006&#039;

                player castingPlayer
        endglobals
        
        struct Orbs
                unit caster
                unit Orb
                real x
                real y
        endstruct
        
        private function o_check takes nothing returns boolean
                return IsUnitEnemy(GetFilterUnit(),castingPlayer) and GetUnitState(GetFilterUnit(),UNIT_STATE_LIFE) &gt; .465
        endfunction
        
        private function t_callback takes nothing returns nothing
                local timer t = GetExpiredTimer()
                local unit temp
                local group g = CreateGroup()
                local Orbs o = GetTimerStructA(t)
                local real x = GetUnitX(<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite12" alt="o_O" title="Er... what?    o_O" loading="lazy" data-shortname="o_O" />rb)
                local real y = GetUnitY(<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite12" alt="o_O" title="Er... what?    o_O" loading="lazy" data-shortname="o_O" />rb)
                local unit dummy
                
                call UnitAddAbility(dummy,CL_AID)
                //Check to see if orb is at the end of its path
                if x &lt; o.x + 100 and x &gt; o.x - 100 and y &gt; o.y - 100 and y &lt; o.y + 100 then
                        call PauseTimer(t)
                        //
                        call o.destroy()
                        call ClearTimerStructA(t)
                        call DestroyTimer(t)
                        set t =null
                else
                        call GroupEnumUnitsInRange(g,x,y,300.0,Condition(function o_check))
                        set temp = GroupPickRandomUnit(g)
                        if temp != null then
                             dummy = CreateUnit(GetOwningPlayer(GetTriggerUnit()),DUMMY_UID,x,y,270.0)
                             set castingPlayer = GetOwningPlayer(o.caster)
                             call IssueTargetOrder(dummy,&quot;chainlightning&quot;,temp)
                             call UnitApplyTimedLife(dummy, &#039;BTLF&#039;, 5)
                        endif
                endif
                set t = null
                call DestroyGroup(g)
                set g =null
                set temp =null
                //call o.destroy()
                set dummy = null
        endfunction
        
        private function Conditions takes nothing returns boolean
                return GetSpellAbilityId() == ORBS_AID
        endfunction

        private function Actions takes nothing returns nothing
                local Orbs o = Orbs.create()
                local timer t = CreateTimer()
                local location l = GetSpellTargetLoc()
                local unit Orb 
                set o.caster = GetTriggerUnit()
                set o.x = GetLocationX(l)
                set o.y = GetLocationY(l)
                set Orb = CreateUnit(GetOwningPlayer(o.caster),ORBS_UID,GetUnitX(o.caster),GetUnitY(o.caster),270.0)
                set <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite12" alt="o_O" title="Er... what?    o_O" loading="lazy" data-shortname="o_O" />rb = Orb
                call IssuePointOrder(Orb,&quot;move&quot;,o.x,o.y)
                call SetTimerStructA(t,o)
                //call o.destroy()
                call TimerStart(t,.25,true,function t_callback)
                
                set t = null
                call RemoveLocation(l)
                set l = null
                set Orb = null
                
        endfunction

        //===========================================================================
        public function InitTrig takes nothing returns nothing
            local trigger t = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
            call TriggerAddCondition(t, Condition( function Conditions ) )
            call TriggerAddAction(t, function Actions )
        endfunction
endscope

A timer callback doesn't have a TriggeringUnit.
 

Matemeo

New Member
Reaction score
20
Lets play another round :banghead:

Still not working, same issues, for testing, I changed the dummy units properties so it'd show up, shouldn't I at least be able to see them spawn, and 5 seconds later die? Because when I cast, no dummys are spawned, as far as I can tell

EDIT: And tests show that it gets to the point where it should spawn a dummy FYI
 

Vexorian

Why no custom sig?
Reaction score
187
Almost working :)

One final problemo, I've noticed this with past spells as well.

JASS:
 private function o_check takes nothing returns boolean
               return IsUnitEnemy(GetFilterUnit(),castingPlayer) and GetUnitState(GetFilterUnit(),UNIT_STATE_LIFE) &gt; .465
      endfunction


This would only return units that are enemies of me, and are alive, correct?

because it doesn't work right now, but if i set it to return true, it does work.

Thanks for all the help :D


Should assign castingplayer before calling the group enum.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top