• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] Please help me out on this little TimerUtilEx question

Status
Not open for further replies.
Level 14
Joined
Apr 20, 2009
Messages
1,543
Imagine the following scenario:

JASS:
scope myScope initializer init
    globals
        private myStruct globalHurray = 0
    endglobals

    struct myStruct
        integer itteration = 1
        boolean someCondition

        method onDestroy takes nothing returns nothing
            set this.itteration = 0
            set this.someCondition = false
        endmethod
    endstruct

    private function enumFunc takes nothing returns nothing
        local myStruct hurray = globalHurray
        set hurray.someCondition = true
        set globalHurray = hurray
    endfunction

    private function timerFunc takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local myStruct hurray = GetTimerData(t)
        set globalHurray = hurray
        call EnumDestructablesInRect(some kinda rect, some kinda filter, function enumFunc)
        call BJDebugMsg(I2S(hurray.itteration))
        if (!someCondition) then
            set hurray.itteration = hurray.itteration + 1
        else
            set hurray.itteration = hurray.itteration - 1
        endif
        if (hurray.itteration == 0) then
            call BJDebugMsg("stop this nonsense")
            call hurray.destroy()
            call ReleaseTimer(t)
        endif
    endfunction

    private function init takes nothing returns nothing
        local timer t = NewTimer()
        local myStruct hurray = myStruct.Create()
        call SetTimerData(t, hurray)
        call TimerStart(t, 0.2, true, function timerFunc)
    endfunction
endscope

Now even though the timer is released (recycled), which should pause the timer (which it doesn't for some reason).
It seems that call BJDebugMsg(I2S(hurray.itteration)) displays a continuous negative value even after the timer is released and the struct is destroyed.
Now here comes the strange part: when I create a new struct and a new timer for some reason someCondition seems to be still true because it instantly destroys the new struct and restarts counting downwards.

Does anybody have an idea why this keeps happening?



EDIT: Nevermind my question, please ignore this thread I see that I did something very stupid in my code :D
I exidentally
JASS:
set t = null
before
JASS:
if (hurray.itteration == 0) then
            call BJDebugMsg("stop this nonsense")
            call hurray.destroy()
            call ReleaseTimer(t)
endif
no sh!t the timer didn't stop...

Problem solved. My mistake. If someone could close this thread it would be appreciated.
 
Last edited:
Level 23
Joined
Apr 16, 2012
Messages
4,041
uninitialized variable is less then null, its plenty nothing and trying to call a function with uninitialized variable may(most likely will) crash the game or at least the thread

to be more correct, null is a 0 value in ram(nothing, null) but uninitialized variable has is stored in a random block of memory mostly out of bounds, like 0x6E42F4 or bigger
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
You should also care that new vars that you dont give a value are 0/null/false by default. So if you forget to declare it and check for var being true, you can wait endless :p (one of my beginner mistakes)

haha, don't worry it's really logical to me that a variable starts with such default values xD

Nah, I just forgot to remove a set t = null when I created my code. I saw it like less then half a minute after I posted this "question"


uninitialized variable is less then null, its plenty nothing and trying to call a function with uninitialized variable may(most likely will) crash the game or at least the thread

to be more correct, null is a 0 value in ram(nothing, null) but uninitialized variable has is stored in a random block of memory mostly out of bounds, like 0x6E42F4 or bigger

I seem to missunderstand what you are trying to say here, a declared variable is not initialized? It doesn't contain a default value you say?
It's absolutely 0 in size and is in a out of bounds block inside your RAM with a likely offset of 0x6E42F4?
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
As a little off-topic, don't use onDestroy. It creates some silly trigger evaluations, that are slow as hell. Use a custom destroy method instead, put the code into it and call this.deallocate() at the end of the method.

Thanks I didn't know this, +rep ;)
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
I seem to missunderstand what you are trying to say here, a declared variable is not initialized? It doesn't contain a default value you say?
It's absolutely 0 in size and is in a out of bounds block inside your RAM with a likely offset of 0x6E42F4?
nope, by uninitialized I mean like
JASS:
local unit u
if IsUnitType(u) == UNIT_TYPE_HERO then
    call BJDebugMsg("fjdcjcjd")
endif
will never run
this rule doesnt count for arrays or globals(predefined in globals bloxk to be null) so no worries
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
nope, by uninitialized I mean like
JASS:
local unit u
if IsUnitType(u) == UNIT_TYPE_HERO then
    call BJDebugMsg("fjdcjcjd")
endif
will never run
this rule doesnt count for arrays or globals(predefined in globals bloxk to be null) so no worries

That actually sounds very logical, in most programming languages it will cause a problem when variables that are not set to a value are equated. Usually however there are default values for whenever a variable gets declared so thanks for the tip on global and array variables in this case.

Nestharus said:
it's a thread crash, not a game crash

I was about to test it out anyways, thanks for the confirmation.
 
Status
Not open for further replies.
Top