HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Dynamic Array Reals Bug

10-15-2007, 09:52 AM#1
Pyrogasm
So, I have this spell. It's rather simple; it shoots a fireball in target direction stunning the first unit it runs into. The only problem is that it doesn't work right in any shape or form.

I originally tested the map with code like this:
Expand JASS:
I cast the spell and nothing happened. The fireball showed up for a split second (the fireball is a dummy unit) and then disappeared. I thought that was odd, so I added in some debug messages:
Expand JASS:
And the game told me that the new X was something like 5912095214521319320000000000000000000000000000. Weird. So I added more debug messages:
Expand JASS:
And it told me this:
Zoom (requires log in)
Essentially saying that 296.00 + (15.50*0.996) = 13194142720000.000 and that -671.750 + (15.50*-0.091) = -46168832000000000000.000.

Being thus flummoxed, I decided to add in a new layer of checking:
Expand JASS:

Once again, this code compiled fine and neither the World Editor nor my janky Syntax Checker gave me an error. However, the numbers still persist. On the first cast, the Y values do not increase randomly, but the X's do. The values are not so large (only around 216231500), yet they do not cause the map to crash... which is weird because it's definitely trying to set the X to outside the map bounds (this normally causes a crash).

On the second cast of the spell, the X's are rougly 5912500000000000000000000000000000000 and the game immediately crashes.


Who's got any idea as to why? I know nothing is screwing with this spell because there are only 2 triggers on the map. One is this spell trigger and the other one has only one action: Custom script: call BJDebugMsg(" ").

I invite you to try it out.
Attached Images
File type: jpgPicture 5.jpg (56.9 KB)
Attached Files
File type: w3xFireball.w3x (135.3 KB)
10-15-2007, 10:53 AM#2
Hitchhiker
Collapse JASS:
function Fireball_Callback takes nothing returns nothing
    local timer T = GetExpiredTimer()
    local integer ArrayIndex = GetCSData(T)
    local real X
    local real Y
    local real Offset
    local unit Dummy = GetArrayUnit(ArrayIndex, 3)
    local boolean OutOfBounds = false
    local group G
    local unit U3
    local unit CastDummy
    local integer DummyAbilityId
    local integer Level

    local real cos
    local real sin
    
    call BJDebugMsg("Callback Index: "+I2S(ArrayIndex))

    if GetWidgetLife(Dummy) > 0.405 then
        call BJDebugMsg("Then; Life: "+R2S(GetWidgetLife(Dummy)))
        set Level = GetArrayInt(ArrayIndex, 5)
        set Offset = Fireball_DistancePerInterval(Level)

        set X = GetUnitX(Dummy)
        set Y = GetUnitY(Dummy)
        set cos = GetArrayReal(ArrayIndex, 1)
        set sin = GetArrayReal(ArrayIndex, 2)
        call BJDebugMsg("Old X: "+R2S(X))
        call BJDebugMsg("Old Y: "+R2S(Y))
        call BJDebugMsg("Offset: "+R2S(Offset))
        call BJDebugMsg("MoveCos: "+R2S(cos))
        call BJDebugMsg("MoveSin: "+R2S(sin))
        set X = X+Offset*cos
        set Y = Y+Offset*sin
        call BJDebugMsg("New X: "+R2S(X))
        call BJDebugMsg("New Y: "+R2S(Y))

//        if X < GetRectMinX(bj_mapInitialPlayableArea) then
//            call BJDebugMsg("Set OutOfBounds 1")
//            set OutOfBounds = true
//        elseif X > GetRectMaxX(bj_mapInitialPlayableArea) then
//            call BJDebugMsg("Set OutOfBounds 2")
//            set OutOfBounds = true
//        elseif Y < GetRectMinY(bj_mapInitialPlayableArea) then
//            call BJDebugMsg("Set OutOfBounds 3")
//            set OutOfBounds = true
//        elseif Y > GetRectMaxY(bj_mapInitialPlayableArea) then
//            call BJDebugMsg("Set OutOfBounds 4")
//            set OutOfBounds = true
//        endif

        if not(OutOfBounds) then
            call BJDebugMsg("Not Out of Bounds")

            call SetUnitX(Dummy, X)
            call SetUnitY(Dummy, Y)

            set G = GetArrayGroup(ArrayIndex, 4)
            set bj_stockPickedItemLevel = Level
            set bj_forceRandomCurrentPick = GetOwningPlayer(Dummy)
            call GroupEnumUnitsInRange(G, X, Y, Fireball_CollisionRadius(Level), Condition(function Fireball_Filter))

            set U3 = FirstOfGroup(G)
            if U3 != null then
                call BJDebugMsg("Collision")
                set DummyAbilityId = Fireball_DummyStunSpellId(Level)
                set CastDummy = CreateUnit(bj_forceRandomCurrentPick, Fireball_DummyUnitId(), X, Y, 0.00)
                call UnitAddAbility(CastDummy, DummyAbilityId)
                call SetUnitAbilityLevel(CastDummy, DummyAbilityId, Level)
                call IssueTargetOrder(CastDummy, Fireball_DummyStunSpellOrderString(Level), U3)
                call UnitApplyTimedLife(CastDummy, 'BTLF', 2.00)

                call DestroyEffect(AddSpecialEffect(Fireball_CollideEffectPath(Level), X, Y))
                call KillUnit(Dummy)
                set CastDummy = null
                set U3 = null
            endif

        else
            call BJDebugMsg("Out of Bounds")
            call KillUnit(Dummy)
        endif
    else
        call BJDebugMsg("Else; Life: "+R2S(GetWidgetLife(Dummy)))
        call DestroyGroup(GetArrayGroup(ArrayIndex, 4))
        call DestroyArray(ArrayIndex)
        call PauseTimer(T)
        call DestroyTimer(T)
    endif

    set T = null
    set Dummy = null
endfunction
setting cos/sin first to a variable worked for me
10-15-2007, 12:20 PM#3
blu_da_noob
That would have to do with the 'having to set reals to a variable before return bugging them' thing.

Edit: Just by the way, your thread title is incredibly misleading as this has nothing to do with integers or the max size of them.
10-15-2007, 01:47 PM#4
Vexorian
Looks like integer 2 real got the same bugs as real 2 intger.

Collapse JASS:
    //===================================================================================================
    // Indexes of real types
    //
    function SetArrayReal takes integer id, integer index, real val returns nothing
        set index=id+index
        if (index<8191) then
            set cs_array1[index]=CS_r2i(val)
        elseif (index<16382) then    
            set cs_array2[index-8191]=CS_r2i(val)
        else
            call StoreReal(cs_cache,I2S(-id),I2S(index),val)
        endif
    endfunction
    function GetArrayReal takes integer id, integer index returns real
     local real r
        set index=id+index
        if (index<8191) then
            set r= CS_i2r(cs_array1[index])
        elseif (index<16382) then    
            set r= CS_i2r( cs_array2[index-8191] )
        else
            set r=GetStoredReal(cs_cache,I2S(-id),I2S(index))
        endif
     return r
    endfunction

If you ask me, people shouldn't really be using cscache's dynamic arrays... At least not on things that are not integers.
10-15-2007, 05:29 PM#5
Silvenon
Question: if you're using new gen, why don't you use constant globals instead of all those constant functions? It would save you some space (and will also spare you of that annoying "()" typing)
10-15-2007, 05:59 PM#6
Vexorian
Quote:
if you're using new gen
He isn't.
10-15-2007, 07:14 PM#7
Pyrogasm
Well, I said that I broke the integer limit because I thought the max integer was something like 2235901257012 and I was getting numbers bigger than that which weren't causing the game to crash.


Is it really a bad idea to use Dynamic Arrays for spells, Vexorian? I thought it would be smarter because it avoids gamecache lookup and they aren't permanently taking up space for available indexes.
10-15-2007, 11:58 PM#8
Pyrogasm
Whoo. Double post.

I've fixed the random fuckups with the dynamic arrays' reals and encountered another problem: the spell itself works fine, no errors or anything and all the effects happen as they should.

The problem arises when the same unit casts the spell once and then once more again whilst the first fireball is still in existence. If this happens, the game immediately crashes.

I thought I would try it with two different units casting the spell at the same time to see if it caused a crash, and it turns out that it does not; instead, something far weirder happens. The first timer simply stops running. After both instances have finished, both units can once again cast as normal (though still not at the same time)... but the value of ArrayIndex increases each time.

Normally, the text "Callback ArrayIndex: 2" shows up during the spells, but after doing the above, the message "Callback ArrayIndex: 7" is displayed instead. My guess is that this is because the first array (of which 5 slots are used) is not being destroyed when the timer stops running. Of his, however, I am not sure.

Here's the spell code:
Expand JASS:
10-16-2007, 02:52 AM#9
Vexorian
Quote:
Originally Posted by Pyrogasm
Well, I said that I broke the integer limit because I thought the max integer was something like 2235901257012 and I was getting numbers bigger than that which weren't causing the game to crash.


Is it really a bad idea to use Dynamic Arrays for spells, Vexorian? I thought it would be smarter because it avoids gamecache lookup and they aren't permanently taking up space for available indexes.
It barely fixes gamecache's speed issue but it doesn't deal with the other one, i2u.

I think though that it might be possible to fix it, I dunno.
10-16-2007, 03:29 AM#10
Pyrogasm
So how is it worse than gamecache? Storing/getting things using AttachObject(...) and GetAttachedUnit(...) still uses I2U.


No ideas on the current issue? One thing I forgot to mention is that I commented out the SetUnitX/Y lines to try to eliminate the crash there but to no avail... so it definitely isn't that.
10-16-2007, 09:58 AM#11
Hitchhiker
seems that local unit Dummy = GetArrayUnit(ArrayIndex, 3) is failing when cast 2 times at the same time.
Collapse JASS:
function Fireball_Callback takes nothing returns nothing
    local timer T = GetExpiredTimer()
    local integer ArrayIndex = GetCSData(T)
    //local real X
    //local real Y
    //local real Offset
    local unit Dummy = GetArrayUnit(ArrayIndex, 3)
    // ... only comments here
crashes whereas
Collapse JASS:
function Fireball_Callback takes nothing returns nothing
    local timer T = GetExpiredTimer()
    local integer ArrayIndex = GetCSData(T)
    //local real X
    //local real Y
    //local real Offset
    //local unit Dummy = GetArrayUnit(ArrayIndex, 3)
    // ... only comments here
is not.
10-17-2007, 01:51 AM#12
Pyrogasm
Dumb. It turns out I accidentally deleted the trigger that initialized CSCache at some point or another.

Stupidest mistake I've made in a long time.
10-17-2007, 01:23 PM#13
Vexorian
Quote:
Originally Posted by Pyrogasm
So how is it worse than gamecache? Storing/getting things using AttachObject(...) and GetAttachedUnit(...) still uses I2U.


No ideas on the current issue? One thing I forgot to mention is that I commented out the SetUnitX/Y lines to try to eliminate the crash there but to no avail... so it definitely isn't that.
It's better than gamecache but it is not much better.