• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[vJass] Unable to allocate, WHAT?

Status
Not open for further replies.
Level 13
Joined
Mar 16, 2008
Messages
941
Hey guys, it's me again :p

I'm working on something I'd call an effect stack, meaning you can add effects to a list and them run the entire list at once.
The stuff is actually working, but it seems that Vexorian doesn't like me o.o

That's the code:
JASS:
private struct Stack [STACKS]
        string array path [EPS]
        
        real array x [EPS]
        real array y [EPS]
        unit array target [EPS]
        string array point [EPS]
        location array loc [EPS]
    
        real array wait [EPS]
        real array dur [EPS]
        
        real duration
        real max
        real period
        integer count
        
        integer id
        
        boolean start
        timer tim
        
        static method CreateStack takes nothing returns integer
            local Stack dat = Stack.allocate()
            
            set dat.duration = 0.
            set dat.max = 0.
            set dat.count = 0
            set dat.id = StructCount
            set dat.start = false
            
            set StackArray[StackCount] = dat
            set StackCount = StackCount+1
            
            return StackCount-1
        endmethod
        
        static method AddEffect takes integer stack, real x, real y, string path, real wait, real dur returns nothing
            local Stack dat = StackArray[stack]
            
            set dat.path[dat.count] = path
            set dat.x[dat.count] = x
            set dat.y[dat.count] = y
            set dat.target[dat.count] = null
            set dat.point[dat.count] = null
            set dat.loc[dat.count] = null
            set dat.max = dat.max+wait
            set dat.wait[dat.count] = dat.max
            set dat.dur[dat.count] = dur
            
            set dat.count = dat.count+1
        endmethod
        
        static method AddEffectTarget takes integer stack, unit u, string point, string path, real wait, real dur returns nothing
            local Stack dat = StackArray[stack]
            
            set dat.path[dat.count] = path
            set dat.x[dat.count] = 0.
            set dat.y[dat.count] = 0.
            set dat.target[dat.count] = u
            set dat.point[dat.count] = point
            set dat.loc[dat.count] = null
            set dat.max = dat.max+wait
            set dat.wait[dat.count] = dat.max
            set dat.dur[dat.count] = dur
            
            set dat.count = dat.count+1
        endmethod
        
        static method AddEffectLoc takes integer stack, location l, string path, real wait, real dur returns nothing
            local Stack dat = StackArray[stack]
            
            set dat.path[dat.count] = path
            set dat.x[dat.count] = 0.
            set dat.y[dat.count] = 0.
            set dat.target[dat.count] = null
            set dat.point[dat.count] = null
            set dat.loc[dat.count] = l
            set dat.max = dat.max+wait
            set dat.wait[dat.count] = dat.max
            set dat.dur[dat.count] = dur
            
            set dat.count = dat.count+1
        endmethod
        //---------------------------------------------------------------------------------
        //---------------------------------------------------------------------------------
        static method Run takes nothing returns nothing
            local Stack dat = StackArray[GetTimerIntData(GetExpiredTimer())]
            local integer i = 0
            
            set dat.duration = dat.duration+dat.period
            
            loop
                exitwhen i >= dat.count
                
                if dat.wait[i] <= dat.duration and dat.wait[i] > dat.duration-dat.period then
                    if dat.target[i] != null then
                        call RemoveEffect.execute(AddSpecialEffectTarget(dat.path[i], dat.target[i], dat.point[i]), dat.dur[i])
                    elseif dat.loc[i] != null then
                        call RemoveEffect.execute(AddSpecialEffectLoc(dat.path[i], dat.loc[i]), dat.dur[i])
                    else
                        call RemoveEffect.execute(AddSpecialEffect(dat.path[i], dat.x[i], dat.y[i]), dat.dur[i])                        
                    endif
                endif
                
                set i = i+1
            endloop
            
            if dat.duration >= dat.max then
                call dat.StopStack()
            endif                
        endmethod
        //---------------------------------------------------------------------------------
        //---------------------------------------------------------------------------------
        static method DestroyStack takes integer stack returns nothing
        endmethod
        
        method StopStack takes nothing returns nothing
            call PauseTimer(.tim)
            set .duration = 0.
        endmethod
        
        static method ResumeStack takes integer stack returns nothing
            call TimerStart(StackArray[stack].tim, StackArray[stack].period, true, function Stack.Run)
        endmethod
        
        static method PauseStack takes integer stack returns nothing
            call PauseTimer(StackArray[stack].tim)
        endmethod
        
        static method StartStack takes integer stack, real period returns nothing
            local Stack dat = StackArray[stack]
            
            if not dat.start then
                set dat.start = true
                set dat.period = period
                set dat.tim = AllocateTimer()
                call SetTimerIntData(dat.tim, stack)
                call TimerStart(dat.tim, period, true, function Stack.Run)
            endif
        endmethod
        
        method onDestroy takes nothing returns nothing
        endmethod
        
    endstruct
 //---------------------------------------------------------------------------------
    //--------------------------WRAPPER FUNCTIONS--------------------------------------
    function CreateEffectStack takes nothing returns integer
        return Stack.CreateStack()
    endfunction
    
    function AddEffectToStack takes integer stack, real x, real y, string path, real wait, real dur returns nothing
        call Stack.AddEffect(stack, x, y, path, wait, dur)
    endfunction
    
    function StartEffectStack takes integer stack returns nothing
        call Stack.StartStack(stack, 0.01)
    endfunction
STACKS and EPS are constants, both with the value 50.
AllocateTimer() is some sort of TimerUltis, RemoveEffect is another part of this effect system :p But all that doesn't matter... when I run this script:
JASS:
local integer i = CreateEffectStack()
    
    call AddEffectToStack(i, 0., 0., "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl", 0.2, 1.)
    call AddEffectToStack(i, 0., 0., "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl", 0.2, 1.)
    call AddEffectToStack(i, 0., 0., "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl", 0.5, 1.)
    call AddEffectToStack(i, 0., 0., "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl", 1., 1.)
    call AddEffectToStack(i, 0., 0., "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl", 0.2, 1.)
    
    call StartEffectStack(i)
it works, the effects are shown in this rythm.
BUT, I get a message on the screen:
"Unable to allocate id for an object of type: EffectSystem_Stack"
I mean, it works... why the hell do I get this message?
It has to do something with the allocation (orly?) but I don't know what it is, I never got it before...

Hope anyone can help me, Justify :)

[Edit]PS: Why isn't there a [vJass] prefix in the list? :p
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
allocation means gathering resources to create an object. Typically, this means finding free memory on your computer that can be used to store your object data.

In vjass, a maximum amount of structs can be allocated at the same time. Usually this is 8191. Make sure you destroy structs (call struct.destroy() will de-allocate the memory) when you're no longer using them.
 
Level 13
Joined
Mar 16, 2008
Messages
941
I know that already, the problem is: that is the first! struct allocated in the map, it's done on a testmap and no other triggers are running :/

EDIT: Found it, thought vJass is intelligent enough for this...
STACKS limited the structs to 50 and the array of 50 destroyed it... I thought that vJass will increase the size automaticly to 2500 (50 structs, 50 arrays).
 
Status
Not open for further replies.
Top