CreateBank() Error Check

Blitz3D Forums/Blitz3D Programming/CreateBank() Error Check

deckbottom(Posted 2006) [#1]
What is the best/safest way of error checking
a CreateBank() command?
I would like to make sure of my allocation before I proceed.
Does BankSize() truly represent what was allocated?

Thanks in advance...


big10p(Posted 2006) [#2]
You can't use BankSize() to check because that command itself requires you to pass a valid bank handle to it. Instead, just check the handle after creating the bank, like:
bank = CreateBank(100)
if bank = 0 Then End



deckbottom(Posted 2006) [#3]
Thanks... I will give that a try.


Sir Gak(Posted 2006) [#4]
The solution by big10p is valid for all Blitz commands that return a handle. If the value is 0, it didn't execute properly. This includes all the Create() commands, and the Load commands as well. In theory, it is good practice to check the handle for validity whenever you execute any of these commands, but it seems to me that few people actually code such checks for a valid handle thru a Create/Load command.

I had a program that kept aborting when trying to Draw an aimage. I looked at the LoadImage command, and the file was correct (so I thought). Then I actually read the handle returned, and it said zero (0). Huh? I asked myself. "That image and directory is valid and correct!" went my indignation. But, I finally came down off my high horse and really looked at the image. It was yada-yada.jpg. I was loading yada-yada.png. Computers are SO stupid!

Which leads me to a observation on computers and programming:

Computers don't do what you THOUGHT you told them to do. Instead, they do what you ACTUALLY told them to do, which is not necessarily the same as what you thought you told them to do.


deckbottom(Posted 2006) [#5]
Thanks... I had tried:
If bank = Null Then End

and was surprised when that didn't work. Furthur review of the Null command reference explained why. My self-taught programming skills show up sometimes.

I agree with your computer thought observation, but for me, somedays the thought ain't there either.


Gabriel(Posted 2006) [#6]
My self-taught programming skills show up sometimes.


Perhaps you're just ahead of your time. BlitzMax has a context-sensitive null which is 0, a null string, a null object, etc depending on the datatype which you are comparing to.