Hopefully can you explain the mystery behind the handle <-1 (just curious) (what if it was = -1 or 0?)
http://www.qb64.org/wiki/LOADIMAGEIf you look at the wiki, you’ll see that a handle of -1 is what you get when the image fails to load. (Bad file path, corrupted image, bad format... Lots of reasons for this, but -1 is the “image failed to load” result.)
0 is, of course, an unused handle. It’s never been utilized at all and is the default value you start with.
Valid images are *always* assigned a value < -1 when they load properly, so a good practice is the simple one I posted above: check to see if the handle is less than -1, and if so, free it before reusing it. (After all, you can’t free handles that don’t exist.)
If you want a visible breakdown of whats happening, grab a handful of change. Toss a quarter in a cup and call it “Image&”.
Now, when we talk about Image&, you know I’m talking about that particular quarter. Right? When I ask, “Is Image& heads or tails,” you’d look in the cup and tell me which it is.
Now, throw
another quarter in the cup, and we’ll now call it, “Image&”. We’re finished with the first quarter, so we’ll just reuse the name so I don’t need to make up a new one. Now, is Image& heads or tails?
Now, continue this process for 10,000,000 times....
WHAT?? You can’t? Your cup overfilled at 2817 quarters and won’t hold any more???
.....
This is what your images are doing in memory — just filling up, until theres no place left to hold them.
The only way you can put 10,000,000 quarters in a cup is if you empty that cup before tossing quarters in it each time, and the same holds true with your images. ;D