is there a way to figure out what type a handle is?

Builder Bob

Live free or don't
Reaction score
249
Let's say I have a function like this:

JASS:
function DestroyHandle takes handle h returns nothing
	if IsHandleATrigger(h) == true then
		DestroyTrigger(h)
	elseif IsHandleATimer(h) == true then
		DestroyTimer(h)
	endif
endfunction


How can I make the IsHandleATrigger() and IsHandleATimer() functions? Are there any possibilities?
 

SFilip

Gone but not forgotten
Reaction score
634
Not possible.
Though...what are you trying to do?
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Note that functions like DestroyTrigger etc. can't take handles and must take only their type, meaning anyway you couldn't do it, as it would syntax you.
 

Builder Bob

Live free or don't
Reaction score
249
I see... I suspected as much.

What I am trying to do? Well, nothing that specifically requires this. I just wanted to streamline things, and thought I'd see what my options were.

Now I don't have to bother continuing on that path. Thanks guys.
 

Jazradel

Helping people do more by doing less.
Reaction score
102
You can do this, but it's not worth it.

function Handle2Timer takes handle h returns timer t
return t
endfunction

Would convert it I think. To check what type it is, convert it and see if a native that normally takes that type has a valid return.
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
>>maybe like this, but i doubt that will work
Why create a handle?

JASS:
function H2T takes handle h returns timer
    return h
    return null
endfunction
 

Builder Bob

Live free or don't
Reaction score
249
Hmmm... That's just the way some of the attachment systems return values. Wonder why I didn't think about that before.

It's very interesting by the way. You say it's not worth it Jazradel. In what way do you mean? I don't know much about the return bug. Does it take more time or something to run the function compared to other functions that doesn't exploit the return bug?
 

Builder Bob

Live free or don't
Reaction score
249
I would not recommend you abuse the return bug for this purpose.

I appreciate your concern, but the original post is just an example and is in no way the real way I intend to use this. In fact I don't exactly know how I want to use it yet.

However, I don't want to limit myself by not using every option I have at my disposal. By expanding my knowledge of what's possible, I can find new ways of doing things that I found difficult doing before.


I appreciate this. It shows exactly how you can exploit the return bug, but not what the problems about using it are. Not in words I can understand anyway.

Why the warnings about abusing it at all? I've seen it before. Is it just because it can cause crashes if used wrong, or are there any other reasons?
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
>>Why the warnings about abusing it at all? I've seen it before. Is it just because it can cause crashes if used wrong, or are there any other reasons?
It is the handle stack issue. Damit I cant find any thread about this issue....

Handle stack is... when a handle is recycled, the attached item is still attached to the handle.

Correct me if..
 

Cohadar

master of fugue
Reaction score
209
However, I don't want to limit myself by not using every option I have at my disposal. By expanding my knowledge of what's possible, I can find new ways of doing things that I found difficult doing before.

The only problem is that since wc3 mapping is quite old discipline by now, there is a 99,9% of chance that whatever "options" you came upon have already:
* been tried, found working -> made into a system.
* been tried, found not working -> rejected.

So I would advice you to spend your time looking for what already exists,
because it is 99,9% chance that it will work better than anything you came up yourself.

Btw, H2<something> functions have been discovered to belong in "not working" category.
(except for the H2I of course)
 

Builder Bob

Live free or don't
Reaction score
249
(---)
It is the handle stack issue. Damit I cant find any thread about this issue....

Handle stack is... when a handle is recycled, the attached item is still attached to the handle.
(---)

Does this mean that it's only an issue if you attach something to the handle? So it's not the functions themselves that are the problem?

Stop me when I'm wrong.

A handle is basically an integer that is pointing to an object in the game.
When we create a new object, it's assigned a random(or is there a pattern?) integer value, between somethingLow and somethingHigh. Since we only have a limited amount of integer values to assign, the handles need to be recycled. This is the root of the problem.

However. There shouldn't be any problem if we convert let's say a unit to handle (for some unknown reason), unless we store that handle over time. So let's say we want to store it over time.

The problem occurs if the unit dies, and is replaced with another. If we now convert the handle back to unit, we will get the wrong unit.

This can be worked around by a death event to set the handle to 0, and I'm sure other problems can be worked around as well.

Please correct me where I'm wrong.

The only problem is that since wc3 mapping is quite old discipline by now, there is a 99,9% of chance that whatever "options" you came upon have already:
* been tried, found working -> made into a system.
* been tried, found not working -> rejected.

(---)

I know. That's how it is in most well established disciplines. What I am saying is not that want to make any new discoveries that haven't been made by others. I am merely trying to learn why one way is chosen over another.

That's why I come here asking for help. To make what for some is common knowledge, my knowledge. I find that by asking the question "why" (something I think is far too little asked), I get a deeper understanding which in turn helps me come up with good ways of doing things much easier.

I hear what you say about looking for other people's systems, but I don't believe in blindly using other people's work simply because it works. I need to at the very least understand it, and modify it to better fit my needs if I can.

>>So I would advice you to spend your time looking for what already exists,
because it is 99,9% chance that it will work better than anything you came up yourself.

No code is perfect for every task. Everything have strengths and weaknesses, so relying on other's code completely is just limiting yourself.
 

SFilip

Gone but not forgotten
Reaction score
634
> or is there a pattern?
There always is. Computers don't know about random.

When you create an object, the game assigns a handle id for it, this is somewhat similar to an array index. The first handle id is 0x100000. If that one is already in use by another object you previously created and haven't destroyed then it tries 0x100001, if that one isn't free 0x100002 and so on until it finds one that is unused. The list of all handles is what we know as the handle stack.
Well, it probably (and hopefully) has a more efficient system than just checking every handle in the stack, but you get the idea - first unused ID.

> we will get the wrong unit.
Not necessarily a unit - it can be any handle.

However there is a much bigger problem with using return bugs, at least ones that convert integer to handle. It was proven that this typecast somewhat "confuses" the game - the way it sees it is "WTH, handle popped out of nowhere?!". This can cause handle stack corruption which in turn can make your map end up producing handles with same IDs which, at the very least, completely messes up every H2I attachment system.
H2I is safe though.
 

Builder Bob

Live free or don't
Reaction score
249
> or is there a pattern?
There always is. Computers don't know about random.

When you create an object, the game assigns a handle id for it, this is somewhat similar to an array index. The first handle id is 0x100000. If that one is already in use by another object you previously created and haven't destroyed then it tries 0x100001, if that one isn't free 0x100002 and so on until it finds one that is unused. The list of all handles is what we know as the handle stack.
Well, it probably (and hopefully) has a more efficient system than just checking every handle in the stack, but you get the idea - first unused ID.

> we will get the wrong unit.
Not necessarily a unit - it can be any handle.

However there is a much bigger problem with using return bugs, at least ones that convert integer to handle. It was proven that this typecast somewhat "confuses" the game - the way it sees it is "WTH, handle popped out of nowhere?!". This can cause handle stack corruption which in turn can make your map end up producing handles with same IDs which, at the very least, completely messes up every H2I attachment system.
H2I is safe though.

Ahh! Now I'm starting to get a better picture! This explains why the old attachment systems aren't recommended anymore, and why attaching structs is safe, while handles are not. I agree that it's not possible to work around that problem.

Thanks a lot! Definitely +rep :)

Thanks to everyone who helped get me to understand as well
 

Cohadar

master of fugue
Reaction score
209
The reason things fuckup is because most people don't know that..

A handle is basically an integer that is pointing to an object in the game.

... is actually a false sentence.

handle is an integer pointing to a struct in Jass virtual machine:
JASS:

struct Handle
    void* pointerToInGameObject
    integer referenceCounter 
endstruct


When ever you copy a variable it increases referenceCounter,
when you null a variable it decreases referenceCounter

when referenceCounter reaches zero Handle is automatically recycled.

The problem with gamecache and I2H is that converting a handle to integer will decrease referenceCounter and if you don't keep a reference in some global array the next time you try to retrieve that handle by using I2H you will be pointing to recycled handle instead of the original one == possible game crash

That is why array systems pwn gamecache, and that is why no pro mapper uses I2H any more.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top