QB64 Phoenix Edition
CleanUp Routine, FREEIMAGE, FREEFONT - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: CleanUp Routine, FREEIMAGE, FREEFONT (/showthread.php?tid=2725)



CleanUp Routine, FREEIMAGE, FREEFONT - NakedApe - 05-23-2024

I'm close to having a new game ready for the Works in Progress thread. Level 1 is done! Today though I was working on the cleanUp sub and am having a couple issues. One font that I'm trying to free is crashing the prog with an illegal function message. The sub closes four other fonts that are similarly dimmed and loaded no problem, but not this one. Also in trying to _freeimage one particular array of hardware images, same deal. It closes other image arrays just fine, but not this one. Anything I should be looking for?

The indexing of the arrays is right, so that's not an issue. Freeing them one at a time or in a loop to ubound gives the same error. I'm now a fairly flummoxed ape...  Thanks for any help offered. 

One other thing, the wiki claims that all loaded sounds are freed upon prog termination, though I see some of us are closing out sounds on wrap up. Is it necessary to close sounds or not? Thnx.

EDIT: Nevermind about the FREEFONT issue. I realized I forgot to switch to a system font before attempting ti free em.


RE: CleanUp Routine, FREEIMAGE, FREEFONT - SMcNeill - 05-23-2024

You have to make certain that you aren't trying to free a resource that's still in use somewhere.

For example:

tempscreen = _newimage(600,400,32)
_DEST _tempscreen
_FONT foo

...stuff

_DEST _differentscreen
_FREEFONT foo

That above would still cause issues as foo is the active font for tempscreen, even though tempscreen has now moved into a background position and isn't active.  What you'd need to do first is:

_DEST _tempscreen
_FONT 16 'swap to the default font
_FREEFONT foo

Remove that font from active duty on all screens, and then you shouldn't have any issues with freeing it for good from your program.


RE: CleanUp Routine, FREEIMAGE, FREEFONT - NakedApe - 05-23-2024

Gotcha. Thanks, Steve. And what about the loaded sounds question? Do all loaded sounds need to be _sndclosed or does QB free sounds upon terminating a program as the wiki states?


RE: CleanUp Routine, FREEIMAGE, FREEFONT - SMcNeill - 05-23-2024

(05-23-2024, 05:02 AM)NakedApe Wrote: Gotcha. Thanks, Steve. And what about the loaded sounds question? Do all loaded sounds need to be _sndclosed or does QB free sounds upon terminating a program as the wiki states?

Everything tends to automatically get freed when a program closes and exits memory.  Technically, you don't *HAVE* to write those lines yourself, but a whole lot of folks like to do so, almost on muscle-memory alone, so they just never accidently forget and have it bite them in the butt.  Wink

Think of it just the same as opening and closing a file FOR INPUT or OUTPUT.

Code: (Select All)
OPEN "temp.txt" FOR OUTPUT AS #1
PRINT #1, "Hello World"
Compile.  Run.  Everything works as expected and with zero problems...

...but it just somehow seems incomplete to me!!  CLOSE really isn't *necessary* here, as the end of the program will close that file handle -- but that's like saying, "Gosh, clothes aren't really *necessary* inside your own house!!"    Sure, they might not be, but you sure as hell end up feeling naked without them! 

Big Grin

If I ever write an OPEN statement and it doesn't have a corresponding CLOSE statement in my program, then I was drunk, exhausted, or lazy -- or some combination of all three!  It just doesn't feel right without one, though *technically*, there's actually no issues with leaving them out of your code.

*Technically*, there's nothing saying you have to wear clothes in the comfort of your own home.  The problem comes when you get so comfortable doing it, that you go out to check the mail in the buff and end up getting reported by the neighbors!

Wink


RE: CleanUp Routine, FREEIMAGE, FREEFONT - NakedApe - 05-23-2024

lol, okay, as a naked ape I appreciate your naked analogy. I’ll keep my pants on and close everything that I open. Gracias, señor.   Wink