Author Topic: Q: determining if an image handle is currently being used as the active SCREEN?  (Read 793 times)

0 Members and 1 Guest are viewing this topic.

Offline madscijr

  • Seasoned Forum Regular
  • Posts: 295
When using _FREEIMAGE, per the wiki
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...

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
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.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline madscijr

  • Seasoned Forum Regular
  • Posts: 295
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!