• 🏆 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!

Remove Dying Destructible -> crash

Status
Not open for further replies.
Level 12
Joined
Feb 13, 2009
Messages
386
JASS:
 / [GUI] Remove Dying Destructible -> crash[/b]

Greetings!

I am trying to remove trees on death (to remove a stump) because I place a "sapling" destructible on their place which turns into a tree on season change.

The problem is: whenever I try to remove "event response - dying destructable", the game crashes when I try to chop the tree.

This is my current code:

This is called on map initialization:
[code=jass]    call EnumDestructablesInRectAll( gg_rct_Outdoors, function Trig_RegisterTreeDeath )

The function is:
JASS:
function Trig_RegisterTreeDeath takes nothing returns nothing
    call TriggerRegisterDeathEvent( gg_trg_Woodcutting, GetEnumDestructable() )
endfunction

The trigger "gg_trg_Woodcutting" which starts when a tree is cut:

JASS:
function Trig_Woodcutting_Actions takes nothing returns nothing
    local location locTreePosition
    set locTreePosition = GetDestructableLoc(GetDyingDestructable())
    call CreateDestructableLoc( 'B000', GetDestructableLoc(GetDyingDestructable()), 0, 0.2, 0 )
    call RemoveDestructable( GetDyingDestructable() )
endfunction

//===========================================================================
function InitTrig_Woodcutting takes nothing returns nothing
    set gg_trg_Woodcutting = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Woodcutting, function Trig_Woodcutting_Actions )
endfunction


The problem is with the string:
JASS:
    call RemoveDestructable( GetDyingDestructable() )
which is equal to a GUI "Remove Destructable (Event response - Dying destructable)".

I don't get why does it crash.
 
Last edited:
Greetings!

I am trying to remove trees on death (to remove a stump) because I place a "sapling" destructible on their place which turns into a tree on season change.

The problem is: whenever I try to remove "event response - dying destructable", the game crashes when I try to chop the tree.

This is my current code:

This is called on map initialization:
JASS:
    call EnumDestructablesInRectAll( gg_rct_Outdoors, function Trig_RegisterTreeDeath )

The function is:
JASS:
function Trig_RegisterTreeDeath takes nothing returns nothing
    call TriggerRegisterDeathEvent( gg_trg_Woodcutting, GetEnumDestructable() )
endfunction

The trigger "gg_trg_Woodcutting" which starts when a tree is cut:

JASS:
function Trig_Woodcutting_Actions takes nothing returns nothing
    local location locTreePosition
    set locTreePosition = GetDestructableLoc(GetDyingDestructable())
    call CreateDestructableLoc( 'B000', GetDestructableLoc(GetDyingDestructable()), 0, 0.2, 0 )
    call RemoveDestructable( GetDyingDestructable() )
endfunction

//===========================================================================
function InitTrig_Woodcutting takes nothing returns nothing
    set gg_trg_Woodcutting = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Woodcutting, function Trig_Woodcutting_Actions )
endfunction


The problem is with the string:
JASS:
    call RemoveDestructable( GetDyingDestructable() )
which is equal to a GUI "Remove Destructable (Event response - Dying destructable)".

I don't get why does it crash.

first, the trigger leaks a location...

hmmm... cannot find a problem with that... try saving the destructable in a variable first...
 
Level 9
Joined
Nov 28, 2008
Messages
704
Your trying to remove something that doesnt really exist probably (because it's dead). Try setting it to a variable, and waiting 5 seconds, then removing it. See if it crashes after those 5 seconds and work out a solution from there.
 
Level 12
Joined
Feb 13, 2009
Messages
386
Thank you, I've found a different solution: I just hide it, and resurrect and show when needed. It looks even better this way because I can play death/birth animation when needed so the tree "grows" visually.

Can you tell me where is the leak please? *newb newb* *tip tip*

:p
 
Level 9
Joined
Nov 28, 2008
Messages
704
JASS:
local location locTreePosition
    set locTreePosition = GetDestructableLoc(GetDyingDestructable())
    call CreateDestructableLoc( 'B000', GetDestructableLoc(GetDyingDestructable()), 0, 0.2, 0 )
    call RemoveDestructable( GetDyingDestructable() )

Personally, I dislike locations because of this crap. I advise using x and y if at all possible.

But the proper fix is:

JASS:
local location locTreePosition
    set locTreePosition = GetDestructableLoc(GetDyingDestructable())
    call CreateDestructableLoc( 'B000', GetDestructableLoc(GetDyingDestructable()), 0, 0.2, 0 )
    call RemoveDestructable( GetDyingDestructable() )
    call RemoveLocation(locTreePosition)
    set locTreePosition = null
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
Since I know that you're trying to code with JASS, this is the code using x and y, courtesy of Mooglefrooglian's fixed code:
JASS:
local destructable d = GetDyingDestructable() //You will use this multiple times so you might as well as use a variable.
call CreateDestructable( 'B000',GetDestructableX(d),GetDestructableY(d), 0, 0.2, 0 )
call RemoveDestructable(d)
set d = null //Prevent leaks
 
Status
Not open for further replies.
Top