Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
graceful way to test for a valid image handle such as before doing _FreeImage?
#2
(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.
Reply


Messages In This Thread
RE: graceful way to test for a valid image handle such as before doing _FreeImage? - by DSMan195276 - 11-10-2025, 09:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Test to post a new Thread + question 32 or 64 bit Rudy M 2 541 09-09-2025, 04:10 PM
Last Post: Rudy M
  A strange experience with forum posting an image TempodiBasic 2 536 06-17-2025, 06:01 AM
Last Post: TempodiBasic
  QB64PE programming challenge? auto-convert image to photoreal etch-a-sketch drawing madscijr 9 1,871 02-14-2025, 05:49 PM
Last Post: madscijr
  Got a slow PC? Test these changes, kindly! SMcNeill 7 1,742 05-16-2024, 09:59 PM
Last Post: grymmjack
  When to free an image? James D Jarvis 5 1,151 04-16-2023, 08:55 PM
Last Post: OldMoses

Forum Jump:


Users browsing this thread: 1 Guest(s)