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.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • 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 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