StopChannel safe tweak request.

BlitzMax Forums/BlitzMax Programming/StopChannel safe tweak request.

Grey Alien(Posted 2006) [#1]
StopChannel stops the channel and makes it available for reuse by allocchannel. Skidracer doesn't want to change this behaviour as it acts like "FreeChannel", fair enough. However, would it be possible to at least set the channel variable to null so that if the programmer tries to reuse it (or view it in the debugger), it doesn't work because it's null. This way the "freeing" of the channel is complete, because it ends up null as well.

Failing any changes, perhaps the manual should have a tiny tweak to say that stopchannel frees it up for reuse by allocchannel but doesn't null the variable. I wasted a lot of time figuring out what was going on and don't want others to fall into the same trap.


sswift(Posted 2006) [#2]
StopChannel doesn't work differently from anything else in Max.

In my Sprite system, if you Free() a sprite, but retain a pointer to it, it's freed from the list of sprites, but you can still call the sprite's methods and do things with it.

That's just how Max works. When you call a function it doesn't pass a pointer to the function with the variable's location in memory, so there's no way to set the variable to Null from within a Free() function. And it would be a bad idea to anyway, because from what I've been told that would break the whole OOP paraigm (or maybe the automatic memory management paradigm, I'm not sure), because that would mean now one part of your program thinks it still has this variable it can use, and it will keep trying to use it, but the variable will be Null so either nothing will happen, or the program will crash.

Do I like this? No. Do I agree with you that the help file works? Yes. But do I think the behavior should be changed? No, because it wouldn't be consistent with everything else, and I suspect we'd end up with more bugs.

Of course, a crash makes it easy to pinpoint bugs. This automatic memory management stuff I could happily do without. Three months down the road and I still find it confusing to keep track of stuff. A crash when I try to access something I freed rather than it just continuing to sit happily on the screen in defiance of me with no indication of where in the program things have gone wrong sure would be nice.

But that's not how Max works.


Grey Alien(Posted 2006) [#3]
OK, thanks for the feedback.