HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Non specified unit local crashes thread

08-17-2006, 11:57 PM#1
The_AwaKening
I was using some code in a trigger and found that my thread crashes if a unit variable is never pointed to anything and you check if it is null. For example:

Collapse JASS:
function nullTest takes nothing returns nothing
 local unit u
     if u == null then
        call BJDebugMsg("null")
    else
        call BJDebugMsg("not null")
    endif
    call BJDebugMsg("end thread")
endfunction

I get none of the messages from this because of checking if u==null. I assumed that it was null if never pointed in the first place.

However, this won't crash:
Collapse JASS:
function GroupBool takes nothing returns boolean
    return IsUnitType(GetFilterUnit(),UNIT_TYPE_HERO)
endfunction

function group_test_Actions takes nothing returns nothing
 local group g=CreateGroup()
    call GroupEnumUnitsOfPlayer(g,Player(2),Condition(function GroupBool))
    if FirstOfGroup(g)==null then
        call BJDebugMsg("null")
    else
        call BJDebugMsg("not null")
    endif
    call BJDebugMsg("end")
endfunction
It Displays "not null" and "end"
08-18-2006, 12:01 AM#2
PipeDream
Trying to read any uninitialized variable is a recipe for crash.
08-18-2006, 07:40 AM#3
BertTheJasser
That was known ages before.