HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Warning; Crash bug!

08-12-2006, 02:55 PM#1
vile
I dont know if anyone knows this yet but I urge you to let everyone know about this. If you try to move non existant lightning effects, your game will crash. Not world editor, but the game itself. I had to find this out in the hard way......

Trigger to test and prove:

Collapse JASS:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    local lightning l=AddLightning("LEAS", true, 0, 0, 5, 5)
    local integer i=0
    local integer i2=0
    loop
        call PolledWait(1)
        if i==0 then
            call MoveLightning(l, true, 5, 5, 0, 0)
        else
            call MoveLightning(l,true,84, 83, 32, 32)
        endif
        call BJDebugMsg(I2S(i2))
        if i2==5 then
            call DestroyLightning(l)
        endif
        set i=GetRandomInt(0,1)
        set i2=i2+1
    endloop
endfunction

The result is of course a game crash exactly when 5 is showed on the screen.

Solution:
Set the variable of the lightning to null to prevent leaks because the var will not be null if its not set to null manually.

The only solution is after you set it to null, add a condition that if that var is null, DONT MOVE IT.
Also I tested that if you try to destroy a non existant lightning it doesnt crash, only if you try to MOVE it.

If you want, you can use this function to move lightnings, to prevent any crashes:

Collapse JASS:
function LightningMove takes lightning l, boolean checkvisibility, real x1, real y1, real x2, real y2 returns nothing
    if l!=null then
        call MoveLightning(l,checkvisibility,x1,y1,x2,y2)
    endif
endfunction

Collapse JASS:
function LightningMoveEx takes lightning l, boolean checkvisibility, real x1, real y1, real z1, real x2, real y2, real z2 returns nothing
    if l!=null then
        call MoveLightningEx(l,checkvisibility,x1,y1,z1,x2,y2,z2)
    endif
endfunction

Just make sure to set the var to null!
08-12-2006, 03:09 PM#2
Vexorian
I would say that doing anything on any destroyed handle is unsafe.
08-12-2006, 03:41 PM#3
vile
Yes but only some will actually cause game crashes according to a number of tests I made. Either way this is valuable information. :)
08-12-2006, 03:48 PM#4
iNfraNe
a large number of doing things with nonexisting handles will cause crashes. I'd rather be surprised you dont get a crash than if you do.
08-12-2006, 03:48 PM#5
Vexorian
Maybe this causes crashes but maybe using other already destroyed things cause other kind of problems, the best thing to do is to avoid to use handles that were removed.
08-12-2006, 05:12 PM#6
The)TideHunter(
You dont have a exitwhen in the loop. (Just pointing it out).
08-12-2006, 05:22 PM#7
vile
Eh, its a TEST THREAD, why would i exit the damn test thread for crying out loud.
08-12-2006, 08:54 PM#8
The)TideHunter(
If it parsed, that could of caused the crash. Not much, but a possability, i thought it was worth mentioning. Obviously not.
08-12-2006, 09:24 PM#9
vile
no, it doesnt crash if you parse it just because there isnt an exitwhen.
08-12-2006, 09:41 PM#10
DioD
exitwhen like if then else no exitwhen == exitwhen false

Same problem with all types, you cant move nothing.
Start no timer
Get no string
08-12-2006, 10:14 PM#11
vile
Actually if I start a non existing timer, nothing happens.

We should really make a list of things that causes crashes, could help greatly.
08-12-2006, 11:00 PM#12
Sharingan
? For what?
Sounds like you would have a reason to use an non-existing handle.
08-13-2006, 12:14 AM#13
DioD
Crush or not using unexistant handles unsafe.
08-13-2006, 10:43 AM#14
vile
You guys really didnt notice this, but from a simple CRASH REPORT you moved to why wont I put an exitwhen on the script which has nothing to do with it, and then you keep saying using non existant handles isnt safe. No shit? What the hell does it have to do with me reporting a crash bug. Just let people know about it, you dont have to comment on every tiny thing. That's just spam.
08-13-2006, 10:53 AM#15
PipeDream
Calm down. Anyway, vile's point is quite valid. It's rare that we know why something crashes when it does so having a checklist of things to run down is very useful. If you post the crash log along with a reason, then anyone can match up their own logs with those posted.