Freeing gadgets

BlitzPlus Forums/BlitzPlus Programming/Freeing gadgets

Oso(Posted 2006) [#1]
Please excuse me for being dense. I'm not bad as an algorist but writing interfaces is not my strong point.

You know how you usually assign a variable to a window or gadget as in

x=createwindow or createsomethingorother

and these x can be used in the logical processing of the gadgets.

Well, in a programme which repeatedly creates and frees the same windows, and optionally gadgets within them, in arbitrary sequence all over the place, is it not a good idea to set these variables to zero at the time of freeing their corresponding gadgets ?

Blitz seems to keep a sort of continuously changing stack of gadgets which reuses the same pointers with different gadgets. I had written a programme of the above type and it took me ages to find what was going wrong and why my main event loop was detecting action in the wrong gadgets. Once I did the above trick everything seemed to work perfectly.

I haven't seen this specifically stated anywhere. Am I thinking correctly ?


Matty(Posted 2006) [#2]
After you have freed a gadget, whether you set the variable's value that was holding the handle to zero or not has no impact on anything. However it is useful to set it back to zero after successfully freeing an entity/gadget/object simply so that you have a way of identifying if the entity/gadget/object still exists.

I think you are thinking correctly regarding this.


Oso(Posted 2006) [#3]
Thanks.

I think I understand what is going on now; associated variables and handles should be kept consistent. I'll just work out a general skeleton pattern for all interfaces which suits my programming technique and keep it handy for future use.


David Boudreau(Posted 2007) [#4]
Oso- thank you for your initial post and solution. Although I found out what was going on quickly enough by carefully studying with the debugger, I wasn't sure how to fix this and I was frustrated that BP assigns _the_exact_same_ number to two _different_ handles (of buttons, in my case).

Matty- I have found that it _does_ matter, and that you must specifically set the variables to zero after using FreeGadget on them (otherwise, two different variable handles will often/likely get the exact same number). I'm pretty sure I can provide code to reproduce the problem, if you like. Maybe I was doing something wrong in overall setup, but this was not intuitive and I think it should have worked. Or, this should be noted in the FreeGadget command reference.


Oso(Posted 2007) [#5]
That's a coincidence, David ! I had just this very minute reinstalled Blitz after my son formatted the hard disk. I was checking to see everything worked and there is your post from yesterday.

That damned thing kept me stuck for weeks because in my particular programme it was so intermittent. It's one of those things that are so obvious once you see them. I agree that a comment in the manual about it would not be out of place.


David Boudreau(Posted 2007) [#6]
Yeah something really needs to be done about the Command Reference. I'd have figured that by now, an update would have provided _something_ more than what is there. It's a wonderful product but that is very disappointing... I will try to go through some online here and try to help with what I've learned and experimented with on my own, but I think we deserve an update providing better documentation by now.


David Boudreau(Posted 2008) [#7]
hm it seems my comment to the online doc of the FreeGadget command talking about all this has disappeared or removed/"cleaned up" by an admin(?). I thought I left a comment to the freegadget command saying some recommendation you set the handle to zero again but don't see it now (it's possible I left it under a different command help entry, but after searching I didn't find it).

If it was removed, it's not only an incomplete command reference in the product but we're kind of being robbed of charitably helping ourselves. It's possible I could be wrong about all this and it was removed for a good reason (ie I don't understand something) but like I said it's not intuitive and I never got an explanation so this is strange.