11-10-2025, 09:18 PM
(11-10-2025, 08:58 PM)madscijr Wrote: It leads me to wonder: is there a way to determine if an image handle is valid, other than error trapping?No because it is never safe to do that. Image handles get reused, it's impossible for the code you described to tell the difference between when the original image hasn't been free'd yet or when the image handle _was_ free'd and has since been reused by a completely unrelated `_NewImage` call. This issue also means your `ON ERROR` approach is not safe either, for the same reason - sometimes your second `_FreeImage` call _will_ work, but will be freeing a completely unrelated image you created with `_NewImage` somewhere else in the code.
You simply _have_ to properly track whether an image has been free'd and then avoid doing anything with it after that point. Ex. When you do the first `_FreeImage`, set `image1` to 0, that way the old handle is no longer in the variable when you go to check it again and the stale handle is no longer there to be free'd by mistake.

