HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Is this function known to crash?

01-22-2006, 09:26 PM#1
The_AwaKening
SelectUnitAddForPlayer

The trigger containing this does not crash all the time, but every once in a while. I remembered reading somewhere that it might cause problems. I am also using map optimizer by Vexorian and Widgetizer by Pitzermike. This is the entire trigger. Note that it hasn't been widgetized yet.
Collapse JASS:
function HeroDuel takes nothing returns nothing
local string sfx
local string sfxloc
local unit u=GetEnumUnit()
local player p=GetOwningPlayer(u)
local location l2=GetRandomLocInRect(gg_rct_DuelRegion)
    set sfx="Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl"
    set sfxloc="origin"
    call ShowUnitShow(u)
    call SetUnitLifePercentBJ(u,100)
    call SetUnitManaPercentBJ(u,100)
    call UnitResetCooldown(u)
    call SetUnitPositionLoc(u,l2)
    call DestroyEffect(AddSpecialEffectTargetUnitBJ(sfxloc,u,sfx))
    call RemoveLocation(l2)
    call SelectUnitAddForPlayer(u,p)
    set l2=null
    set sfx=null
    set sfxloc=null
    set u=null
    set p=null
endfunction

function Heroes_Revive takes nothing returns nothing
local location l
local unit u=GetEnumUnit()
local player p=GetOwningPlayer(u)
    if IsUnitDeadBJ(u) then
        if p == Player(0) or p == Player(1) or p == Player(2) then
            set l=GetRectCenter(udg_heroSpawn[1])
            call ReviveHeroLoc(u,l,true)
            call RemoveLocation(l)
        elseif p == Player(3) or p == Player(4) or p == Player(5) then
            set l=GetRectCenter(udg_heroSpawn[2])
            call ReviveHeroLoc(u,l,true)
            call RemoveLocation(l)
        elseif p == Player(6) or p == Player(7) or p == Player(8) then
            set l=GetRectCenter(udg_heroSpawn[3])
            call ReviveHeroLoc(u,l,true)
            call RemoveLocation(l)
        endif
    endif
    if GetUnitTypeId(u) == 'ocat' or GetUnitTypeId(u) == 'nC17' then    
        call ShowUnit(u,true)
        call SetUnitInvulnerable(u,false)
    endif
    set l=null
    set u=null
    set p=null
endfunction

function Trig_PlayerHeroesNew_Actions takes nothing returns nothing
local group g=CreateGroup()
local timerdialog W
local timer T
local string s="Game_Over_In"
local integer i=1
local integer j=0
    call TriggerSleepAction( .01 )
    set T=CreateTimer()
    call CreateTimerDialogBJ( T, s )
    set W=GetLastCreatedTimerDialogBJ()
    loop
        if udg_heroTotalHeros>8 then
            exitwhen i>udg_heroTotalHeros
        else
            exitwhen j>8
        endif
        call GroupAddUnit(g,udg_heroList[i])
        call GroupAddGroup( GetUnitsOfPlayerAndTypeId(Player(j), 'nC17'), g )
        call GroupAddGroup( GetUnitsOfPlayerAndTypeId(Player(j), 'ocat'), g )
        set j=j+1
        set i=i+1
    endloop
    call StartTimerBJ( T, false, 120.00 )
    call TriggerSleepAction( .10 )
    call ForGroup( g, function Heroes_Revive )
    call TriggerSleepAction( .10 )
    call ForGroup( g, function HeroDuel )
    call DestroyGroup(g)
    set g=null
    set s=null
endfunction

//===========================================================================
function InitTrig_PlayerHeroesNew takes nothing returns nothing
    set gg_trg_PlayerHeroesNew = CreateTrigger(  )
    call DisableTrigger( gg_trg_PlayerHeroesNew )
    call TriggerAddAction( gg_trg_PlayerHeroesNew, function Trig_PlayerHeroesNew_Actions )
endfunction

I know also that I could combine the top 2 functions into 1. The only reason it is like that is because it's been added to and I just haven't gotten around to it.
01-24-2006, 03:34 PM#2
The_AwaKening
Since it looks like no one has time to look it over, I'll tell you what I suspect could be trouble and you can tell me if you agree.

In first ForGroup call I am reviving dead heroes, but I didn't have a condition in there for
If IsUnitDeadBJ(GetEnumUnit())
so this means it was trying to revive even the heroes that weren't dead.

I'm also curious about the call
SelectUnitAddForPlayer
being used in a group call to select all picked units for matching players.

This would be easier to fix, but it doesn't happen all the time. I'm just getting crashes every once in a while at this spot.
Thanks in advance for any suggestions you could give.
01-24-2006, 05:01 PM#3
qwertyui
Can't really say from what i can see :/

Do you have crashes sometimes, but not always?

What you can try to - for crash-catching purposes - is spam the trigger text with game-display text functions. Then on the next crash you will be able to more or less pinpoint the culprit function.

To my knowledge, crashes only happen when you attempt to reference an archive/string element with an unacceptable index id.

Hope i helped any :/
01-24-2006, 05:33 PM#4
Vexorian
does it crash when the map is not optimized?
01-24-2006, 10:26 PM#5
The_AwaKening
Hard to say if it crashes without the map optimized since it only happens in about 1 out of 5 games played. I tried beta testing a couple of games without it optimized and it is fine, but then I optimize it to release to public and it crashes once in a while.

The problem is that this trigger only runs at the very end of the game (after about 45 minutes). I have tried reproducing the problem like I said by beta testing before optimization. So far, about 8 or 9 games with no crash.

Here is a shot of what options I am selecting in optimize. Most things I uncheck.
01-25-2006, 12:46 AM#6
Vexorian
you are hardly using any of the important options. I mean if you think you are 'protecting' your map , without correct script obfuscation the map can be 'unprotected' in seconds, leterally.

But oh well since you don't use script obfuscation I highly doubt the optimizer has anything to do with these crashes.

Are you sure that's the trigger that causes the crash?
01-25-2006, 12:57 AM#7
The_AwaKening
I unselected that option because I was getting more crashes with that option selected in earlier versions. I mostly use your program to reduce size more than anything. I'm also about 99% sure that this is the trigger crashing the game.
01-25-2006, 01:15 AM#8
Vexorian
what option ? you unselected a total of 8 options. And things like the shorter variable/function names are great at saving space.


Come back when you are 100% sure.
01-25-2006, 04:29 AM#9
qwertyui
You need to find the exact location and conditions of the crash.
It doesn't seem to be a problem just with the trigger. It seems the crash happens when trigger is ran under a special set of conditions on your map.
01-25-2006, 05:38 AM#10
The_AwaKening
Well I did just notice that I was still using optimizer 3.7b rather than 3.8b. Don't know if that matters or not. I just wanted to know mostly if anything in that code looked suspicious, especially the 2 that I pointed out.
01-25-2006, 01:38 PM#11
Vexorian
well try making sure the unit you try to select is not null or removed
01-25-2006, 02:12 PM#12
ShadowDragon
What event is your trigger using, and how is map crashing? (ie. just crash to desktop, or fatal error)
01-25-2006, 03:19 PM#13
The_AwaKening
Fatal error.

Thanks Vex, that may be the problem. It was trying to select a few units that were being removed beforehand. That may be the problem. 10 tests with not crashes now.