QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: madscijr on February 02, 2022, 10:36:01 am

Title: Q: determining if an image handle is currently being used as the active SCREEN?
Post by: madscijr on February 02, 2022, 10:36:01 am
When using _FREEIMAGE, per the wiki
https://wiki.qb64.org/wiki/FREEIMAGE (https://wiki.qb64.org/wiki/FREEIMAGE)
Quote
Do not try to free image handles currently being used as the active SCREEN. Change screen modes first.

Is there some way to programmatically determine if a given image handle is currently being used as the active SCREEN?

I realize that whenever you change the SCREEN to a new image handle, you could manually set a variable to keep track, and check that before doing _FREEIMAGE,
but is there some built-in command to determine this without having to do that?

Much appreciated...
Title: Re: Q: determining if an image handle is currently being used as the active SCREEN?
Post by: SMcNeill on February 02, 2022, 11:11:36 am
Code: QB64: [Select]
  1. Dim image(5) As Long
  2. For i = 0 To 5
  3.     image(i) = _NewImage(80, 33, 0)
  4.     Screen image(i)
  5.     Cls , i
  6.  
  7.  
  8.     r = Int(Rnd * 6) '0 to 5
  9.     Screen image(r)
  10.     Print "The current screen is image("; r; "), whose handle is:"; image(r); "...   <proven by using direct variables>."
  11.     Print
  12.     Print "Your _DEST is: "; _Dest
  13.     Print "Your _SOURCE is: "; _Source
  14.     Print "The _DISPLAY is: "; _Display
  15.     Sleep

The easiest way would just be to check if the handle is the same as the _DEST, _SOURCE, or _DISPLAY.

_DEST is where you're currently set to print text to.  I don't think you can free that without causing issues.
_SOURCE is where you get information from if you use POINT, SCREEN, or whatnot.  I don't think it can be freed either.
_DISPLAY is the handle of the currently active display.

Check against those 3 things, and if your current handle isn't one of them, then you're safe to free it.
Title: Re: Q: determining if an image handle is currently being used as the active SCREEN?
Post by: madscijr on February 02, 2022, 02:02:49 pm
The easiest way would just be to check if the handle is the same as the _DEST, _SOURCE, or _DISPLAY.
...
Check against those 3 things, and if your current handle isn't one of them, then you're safe to free it.

I didn't realize those could be read as values. That should answer my question - thanks!