• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] onDestroy causing a crash?

Status
Not open for further replies.
Level 4
Joined
Jun 8, 2007
Messages
89
Ok, so I have a struct and when I do this:
JASS:
if (sp.wait < 0.0) then
                    call BJDebugMsg("destcall")
                    call sp.destroy()
                endif

then the game will crash without showing any debug messages, but if I comment out call sp.destroy(), then it will show the message "destcall" as it should, thus leading me to believe onDestroy is crashing my game. The struct is spcast, and I have no idea why this wont work. I've done this a lot before, and the only real difference now is the use of static variables. Is it possible this is the problem?

JASS:
        private method onDestroy takes nothing returns nothing
            call BJDebugMsg("destroy")
            // remove from the array
            set spcast.ActiveCastArray[spcast.Index]        = spcast.ActiveCastArray[spcast.ActiveCasters - 1]
            set spcast.ActiveCasters                        = spcast.ActiveCasters - 1
        
            // add caster to idle if it isn't full
            if (spcast.IdleCasters < DUMMY_UNIT_INACTIVE_LIMIT) then
                // remove the ability first
                //call UnitRemoveAbility(.caster, .abilityId)
                // now add to the idle
                set spcast.IdleCasterArray[spcast.IdleCasters]  = .caster
                set spcast.IdleCasters                          = spcast.IdleCasters + 1
                
                call BJDebugMsg("destroySave")
            else
                //call RemoveUnit(.caster)
                call BJDebugMsg("destroyRemove")
            endif
            
            // nullify
            set .caster     = null
            set .target     = null
            set .owner      = null
        endmethod

Thanks in advance!
 
Level 4
Joined
Jun 8, 2007
Messages
89
Well, if I comment out both
JASS:
//call UnitRemoveAbility(.caster, .abilityId)
and
JASS:
set spcast.IdleCasterArray[spcast.IdleCasters]  = .caster
using the proper indexes of only '0'. This led me to find out that I was checking something with a >= 0 rather than simply > 0, which seems to fix the crash, but now I have another issue.

If I create a unit and add an ability, can I immediately use IssueTargetOrder(), or do I have to do something first (such as give the unit a split second to create or call some other function on it)?
 
Status
Not open for further replies.
Top