Giving an order crashes the game

BlueMirage

Trust, but doubt.
Reaction score
39
The spell does the following: You'll need to use a subskill called Set Destination. When using Travel, your hero will move towards the destination you previously set with extra movespeed and no collision. Travel is based on Berserk, and provides the extra movespeed and a fluent way of casting the spell. You lose these bonuses when you've traveled 35% of the distance (Assuming the terrain has no cliffs), or when you either give the unit any order while Travel is in effect.

The spell works almost flawlessly. It'll cancel correctly if the timer runs out, but if you activate the function TravelStop through giving the unit an order, the game crashes.

JASS:
function TravelStop takes nothing returns nothing
    local unit u
    local timer tim = GetExpiredTimer()
    local trigger t
    local integer i

    if tim == null then //You gave the unit an order

        set t = GetTriggeringTrigger()
        set u = GetTriggerUnit()
        set tim = LoadTimerHandle(udg_Hashtable, GetHandleId(t), 0)
        call FlushChildHashtable(udg_Hashtable, GetHandleId(tim))

    else //You did not give the unit an order. Timer expired

        set i = GetHandleId(tim)
        set u = LoadUnitHandle(udg_Hashtable, i, 0)
        set t = LoadTriggerHandle(udg_Hashtable, i, 1)
        call FlushChildHashtable(udg_Hashtable, i)

    endif

    call FlushChildHashtable(udg_Hashtable, GetHandleId(t))
    call EndTimer(tim) //Custom function that pauses and destroys a timer, nothing else.
    call TriggerClearActions(t)
    call DestroyTrigger(t)

    call UnitRemoveAbility(u, 'B00G') //Movespeed buff
    call SetUnitPathing(u, true)

    set u = null
    set t = null
    set tim = null
endfunction

function WandererCast takes nothing returns boolean
    local integer i = GetSpellAbilityId()
    local trigger t
    local unit u
    local timer tim
    local real x
    local real y

    if i == 'A014' then //Set Destination

        set i = GetHandleId(GetTriggerUnit())
        call SaveReal(udg_Hashtable, i, StringHash("TravelX"), GetSpellTargetX())
        call SaveReal(udg_Hashtable, i, StringHash("TravelY"), GetSpellTargetY())

    elseif i == 'A015' then //Travel

        set u = GetTriggerUnit()
        set i = GetHandleId(u)
        set x = LoadReal(udg_Hashtable, i, StringHash("TravelX"))
        set y = LoadReal(udg_Hashtable, i, StringHash("TravelY"))

        call IssuePointOrder(u, "move", x, y)
        call SetUnitPathing(u, false)

        set tim = CreateTimer()
        set t = CreateTrigger()

        set i = GetHandleId(tim)
        call SaveUnitHandle(udg_Hashtable, i, 0, u)
        call SaveTriggerHandle(udg_Hashtable, i, 1, t)
        //Save handles so that they can be destroyed

        //Note that the timer and the trigger runs the same function, TravelStop.
        call TimerStart(tim, (0.35 * Distance(x, y, GetUnitX(u), GetUnitY(u)) / GetUnitMoveSpeed(u)) / 1.4, false, function TravelStop)

        call SaveTimerHandle(udg_Hashtable, GetHandleId(t), 0, tim)
        call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_ISSUED_TARGET_ORDER)
        call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_ISSUED_POINT_ORDER)
        call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_ISSUED_ORDER)
        call TriggerAddAction(t, function TravelStop) //It'll run TravelStop if the unit is given an order

        set u = null
        set t = null
        set tim = null

    endif

    return false
endfunction
 

luorax

Invasion in Duskwood
Reaction score
67
JASS:
i == 'A014' then //Set Destination


You forgot about the "if". Maybe this causes the problem...
 

BlueMirage

Trust, but doubt.
Reaction score
39
Is this a copy-past mistake or?: i == 'A014' then //Set Destination
Yeah it's a copy-pasta mistake. The code compiles without problems, so I can't have missed it in the real trigger. ^^ I'll fix that typo.

I'll try disabling the trigger before destroying it.

Nope, the game still crashes.

EDIT: You don't suppose it's because I'm not using any condition for my local trigger?
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
>You don't suppose it's because I'm not using any condition for my local trigger?

Nope. It can't be that.

Leave only the last from those and then test the script:
JASS:
//call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_ISSUED_TARGET_ORDER)
//call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_ISSUED_POINT_ORDER)
call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_ISSUED_ORDER)


If it still crashes then:
Try to comment out/disable different parts of the script and then test it, hopefully it won't crash the game at some point.

My theory is that EVENT_UNIT_ISSUED_ORDER fires before EVENT_UNIT_ISSUED_POINT_ORDER or EVENT_UNIT_ISSUED_TARGET_ORDER but then the trigger is disabled and destroyed thus crashing something : P.
Make a different trigger for every event:
call TriggerRegisterUnitEvent(t1, u, EVENT_UNIT_ISSUED_TARGET_ORDER)
call TriggerRegisterUnitEvent(t2, u, EVENT_UNIT_ISSUED_POINT_ORDER)
call TriggerRegisterUnitEvent(t3, u, EVENT_UNIT_ISSUED_ORDER)
 

BlueMirage

Trust, but doubt.
Reaction score
39
The three events (four, but the fourth is a timer) of that trigger are:

Unit u gets an order targeting an object
Unit u gets an order targeting a point
Unit u gets an order with no target

I disabled the first two like you told me to. Naturally, the game doesn't crash if I use Move to while the spell is in effect, but the effect doesn't stop either.
So, I used what I knew would activate the event. I pressed Stop while the spell was in effect. The game crashed.

Given this information, we can conclude that the following is not a functional solution:

I'll try to comment it as much as possible, and give a brief spell description.
I'm not too good at commenting though.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Well, there are a couple of bad things about this whole spell...
One is that you're creating triggers dynamically, which is really bad as events leak, and you cannot destroy them...

To prevent this I would first like to ask you to post the entire spell, with the Init function as well, and then you should make a single trigger there, with the events registered, and also a condition checking if Triggering unit is in a group or something, and instead of creating the trigger and registering the events in the "WandererCast" function, you simply add the unit to the global group, and in the "TravelerStop" function, you remove him from the group ;)

Then there's the whole crash-related problem you're having, which I probably will need the entire code for ;)
 

Laiev

Hey Listen!!
Reaction score
188
[ljass]call TriggerRemoveAction[/ljass] - not sure but this may cause trigger stack
[ljass]call TriggerRemoveCondition[/ljass] - safe from trigger stack
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
>Doesn't ResetTrigger() remove the events from a trigger?

Not tested it but I think it resets the eval and exec count? (will test it later)

Edit: yup it resets/sets them to zero : )
 

BlueMirage

Trust, but doubt.
Reaction score
39
There is a lot that I don't know about how JASS actually works. I just know some of the results it can bring.
One is that you're creating triggers dynamically, which is really bad as events leak, and you cannot destroy them...
I've read that it was like that, but I thought it would clear up as long as the trigger was destroyed seeing as there is no native for destroying events. Assuming there is absolutely no way to remove these leaks, I think I know where most of my leaks come from as it is a technique I use often.

I really don't like using globals for every spell that I have as I, for some reason, can only use the basic WC3 editor. I tried Newgen but I could never test any map with it.
call TriggerRemoveAction - not sure but this may cause trigger stack
Not tested it but I think it resets the eval and exec count? (will test it later)
How exactly does the trigger stack work? What's Eval and Exec count?

As requested, here's the full spell. Or more like hero, I keep all of my spells in a single trigger for the hero (Not going to bother giving major comments, refer to first post if you need those):
JASS:
function TravelStop takes nothing returns nothing
    local unit u
    local timer tim = GetExpiredTimer()
    local trigger t
    local integer i

    if tim == null then

        set t = GetTriggeringTrigger()
        set u = GetTriggerUnit()
        set tim = LoadTimerHandle(udg_Hashtable, GetHandleId(t), 0)
        call FlushChildHashtable(udg_Hashtable, GetHandleId(tim))

    else

        set i = GetHandleId(tim)
        set u = LoadUnitHandle(udg_Hashtable, i, 0)
        set t = LoadTriggerHandle(udg_Hashtable, i, 1)
        call FlushChildHashtable(udg_Hashtable, i)

    endif

    call FlushChildHashtable(udg_Hashtable, GetHandleId(t))
    call EndTimer(tim)

    call TriggerClearActions(t)
    call DestroyTrigger(t)

    call UnitRemoveAbility(u, 'B00G')
    call SetUnitPathing(u, true)

    set u = null
    set t = null
    set tim = null
endfunction

function WandererCast takes nothing returns boolean
    local integer i = GetSpellAbilityId()
    local trigger t
    local unit u
    local timer tim
    local real x
    local real y

    if i == 'A00B' then //Throat Cut

        call PhysDmg(GetTriggerUnit(), GetSpellTargetUnit(), 135., true)

    elseif i == 'A014' then //Set Destination

        set i = GetHandleId(GetTriggerUnit())
        call SaveReal(udg_Hashtable, i, StringHash("TravelX"), GetSpellTargetX())
        call SaveReal(udg_Hashtable, i, StringHash("TravelY"), GetSpellTargetY())

    elseif i == 'A015' then //Travel

        set u = GetTriggerUnit()
        set i = GetHandleId(u)
        set x = LoadReal(udg_Hashtable, i, StringHash("TravelX"))
        set y = LoadReal(udg_Hashtable, i, StringHash("TravelY"))

        call IssuePointOrder(u, "move", x, y)
        call SetUnitPathing(u, false)

        set tim = CreateTimer()
        set t = CreateTrigger()

        set i = GetHandleId(tim)
        call SaveUnitHandle(udg_Hashtable, i, 0, u)
        call SaveTriggerHandle(udg_Hashtable, i, 1, t)
        call TimerStart(tim, (0.35 * Distance(x, y, GetUnitX(u), GetUnitY(u)) / GetUnitMoveSpeed(u)) / 1.4, false, function TravelStop)

        call SaveTimerHandle(udg_Hashtable, GetHandleId(t), 0, tim)
        //call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_ISSUED_TARGET_ORDER)
        //call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_ISSUED_POINT_ORDER)
        //call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_ISSUED_ORDER)
        call TriggerAddAction(t, function TravelStop)

        set u = null
        set t = null
        set tim = null

    endif

    return false
endfunction

function LoopCloak takes nothing returns nothing
    local timer tim = GetExpiredTimer()
    local integer i = GetHandleId(tim)
    local unit u = LoadUnitHandle(udg_Hashtable, i, 0)
    local real r = LoadReal(udg_Hashtable, i, 1) + 0.25
    local integer lev = GetUnitAbilityLevel(u, 'A00R')

    if IsUnitSeen(u) or GetUnitAbilityLevel(u, 'B00D') > 0 or GetWidgetLife(u) <= 0 then
        call SaveReal(udg_Hashtable, i, 1, 0.)
        set tim = null
        set u = null
        return
    endif

    if r >= 4.25 - (lev * 0.25) then
        call DummySpell(u, 'A00S', "invisibility", 1)
        call UnitResetCooldown(u)
    else
        call SaveReal(udg_Hashtable, i, 1, r)
    endif


    set u = null
    set tim = null
endfunction

function WandererLearn takes nothing returns boolean
    local timer t
    local trigger trig
    local integer skill = GetLearnedSkill()
    local integer level = GetLearnedSkillLevel()
    local unit u = GetTriggerUnit()
    local integer i

    if level == 1 then

        if skill == 'A00R' then //Cloak

            set t = CreateTimer()

            call TimerStart(t, 0.25, true, function LoopCloak)
            call SaveUnitHandle(udg_Hashtable, GetHandleId(t), 0, u)
            set t = null

        elseif skill == 'A015' then //Travel learned
            call SetPlayerAbilityAvailable(GetOwningPlayer(u), 'A014', true)
            set i = GetHandleId(u)
            call SaveReal(udg_Hashtable, i, StringHash("TravelX"), 0.)
            call SaveReal(udg_Hashtable, i, StringHash("TravelY"), 0.)
        endif

        if GetUnitAbilityLevel(u, 'A00R') >= 1 and GetUnitAbilityLevel(u, 'A015') >= 1 then
            set trig = GetTriggeringTrigger()
            call TriggerClearConditions(trig)
            call DestroyTrigger(trig)
            set trig = null
        endif

    endif

    set u = null

    return false
endfunction

function Start_Wanderer takes nothing returns nothing //Run with ExecuteFunc() after selecting the hero.
    local trigger t = CreateTrigger()
    local trigger t2 = CreateTrigger()

    call TriggerRegisterUnitEvent(t, udg_TempUnit, EVENT_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function WandererCast))

    call TriggerRegisterUnitEvent(t2, udg_TempUnit, EVENT_UNIT_HERO_SKILL)
    call TriggerAddCondition(t2, Condition(function WandererLearn))

    call UnitAddAbility(udg_TempUnit, 'A014') //Set Destination subskill
    call SetPlayerAbilityAvailable(GetOwningPlayer(udg_TempUnit), 'A014', false)

    set t = null
    set t2 = null
endfunction

function InitTrig_Wanderer takes nothing returns nothing
endfunction
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
Did you try those combos?

JASS:
//call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_ISSUED_TARGET_ORDER)
//call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_ISSUED_POINT_ORDER)
call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_ISSUED_ORDER)


JASS:
//call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_ISSUED_TARGET_ORDER)
call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_ISSUED_POINT_ORDER)
//call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_ISSUED_ORDER)


JASS:
call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_ISSUED_TARGET_ORDER)
//call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_ISSUED_POINT_ORDER)
//call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_ISSUED_ORDER)


The trigger evaluation and execution counts are some fields of the trigger struct/object/handle that I haven't found usefull at all. They count (supposedly) how many times the trigger has run it's condition(eval) and action(exec) function.

The logic behind it beats me because the condition and action function can be triggered by the event itself and also by the TriggerEvaluate and TriggerExecute functions and if the trigger has none or 1 or both a condition and action function it's kinda complicated to work out each case to track (guess) how they(eval and exec counts) are incremented. (A peculiar case is that if the trigger has neither a condition nor an action function and you call TriggerExecute(the_trigger) it's eval and exec count goes to 1 but if you call TriggerExecute(the_trigger) again eval and exec count don't change (so I guess they are assigned a value of 1).

You can get them with those btw:
JASS:
constant native GetTriggerEvalCount     takes trigger whichTrigger returns integer
constant native GetTriggerExecCount     takes trigger whichTrigger returns integer


Perhaps you could try to avoid the case where the player changes the Travel destination by ordering the unit something. So yeah disable player control over the unit while travel is in effect? I think channel has such an option or was it something else...idr.

Edit:
attached a table with some insight about eval and exec

Guess TriggerEvaluate is sorta "bugged" due to not increasing the eval count of the trigger.
 

Attachments

  • trigger_eval_exec_table.txt
    2.7 KB · Views: 184

BlueMirage

Trust, but doubt.
Reaction score
39
Did you try those combos?
I did not. I will go try them.
Perhaps you could try to avoid the case where the player changes the Travel destination by ordering the unit something. So yeah disable player control over the unit while travel is in effect?
Giving an order while using Travel only cancels it, it doesn't change the direction.
While that would be a possible solution, it would not be optimal. Travel is a skill that with some good foresight can be used as a very powerful blink tool. Without the ability to cancel mid-Travel, it'll be harder to use for chasing as it is possible that you would run past your enemy without the chance to stop.
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
>Without the ability to cancel mid-Travel, it'll be harder to use for chasing as it is possible that you would run past your enemy without the chance to stop.

Good point.

Does it crash if you don't disable the trigger in the TravelStop function?:
JASS:
     .
     .
     .
    call EndTimer(tim)

    call TriggerClearActions(t)
    //call DestroyTrigger(t)
    .
    .
    .
 

BlueMirage

Trust, but doubt.
Reaction score
39
Did you try those combos?
Tried them now. They all crash.
Does it crash if you don't disable the trigger in the TravelStop function?
Disable != Destroy. Since you're saying DestroyTrigger in the code, I'll try disabling that.
Yes it crashes.
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
>Disable != Destroy. -> true : )
Yea I meant DestroyTrigger as in the code

My last idea is to comment out this line from the TravelStop function. No logic behind it just a guess:
[ljass] call TriggerClearActions(t)[/ljass]
 

Ashlebede

New Member
Reaction score
43
[ljass]BJDebugMsg()[/ljass]'s. Add [ljass]BJDebugMsg()[/ljass]'s after every step in your function, so you know where it crashes. For instance :

JASS:
function foo takes nothing returns nothing
  local unit u=GetTriggerUnit()
  call BJDebugMsg("Var declaration works.")

  if u==udg_myUnit then
    call BJDebugMsg("Condition works.")
    call SetUnitX(u,0.)
    call SetUnitY(u,0.)
    call BJDebugMsg("Setting position works.")
  endif
endfunction


That way you can find out exactly where there is a problem in your code and focus only on that part of the function instead of knowing only the vague fact that this function makes the game crash somewhere for some reason.
 

BlueMirage

Trust, but doubt.
Reaction score
39
It won't help much, as I won't even see the debugs due to the game crashing instantly. I won't get to see the messages.
 

Ashlebede

New Member
Reaction score
43
There is usually a delay between when the game freezes and when it closes. But anyways, you can still do [ljass]BJDebugMsg()[/ljass]+[ljass]PolledWait()[/ljass]. If it still crashes right away you know it bugs at the very beginning of the function! =D<<
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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 The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top