Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change font size / Maintain screen size.
#5
(11-11-2022, 03:18 PM)SMcNeill Wrote: Your program is doomed to fail.  It's gonna crash and burn horribly after being used for a while.  Just watch it's memory usage go up, up, up, up, and up more, in task manager.

You're endlessly loading resources -- fonts at various sizes, in this example -- and never freeing them.  You've got a memory leak at work here that will eventually either crash your program, or else make your OS slow down to a crawl and become unstable.

My advice?  Since your fontsize is going from 9 to 31, just load the font into an array at startup and use that array without having to worry about ever freeing or loading resources after that.

DIM font(9 TO 31) As Long
For I = 9 TO 31 STEP 2
  font(i) = _LOADFONT(fontpath$, i, fontstyle$)
NEXT

Then just call your _FONT font(fontsize).  No endless loading of resources necessary, nor any need to free them.

I noticed that too, The _DELAY helped prevent crashing, but if removed and keys tapped rapidly, I'd get a crash in about 10 tries!
I was wondering if the _FREEFONT statement was faulty or since I haven't used it in a few years if I'd forgotten something about it. I went back to a WP routine and found _FONT 16: _FREEFONT FONT&. _FONT 16? Went to the wiki and read the part where you need to change the font before you can free a font. Makes sense, sort of a prisoner swap. Anyway, put that in and solved the memory leak.

I thought about using arrays, too. I would have been more excited if I could also use arrays to pre-configure the window sizes. Yes, I could just set up a database of font widths and heights, but it would be nice for the resources to pull those values. I believe that means calling them, which again temporarily changes the window size. What I'm looking for, holy grail-wise, is a way to make the window never move or change size during a font size change. That's difficult to accomplish.

I do want to give the array method a whirl and compare the results to see if it provides a better path forward. I'll post back later today with an update, thanks!

Pete
Reply


Messages In This Thread
RE: Change font size / Maintain screen size. - by Pete - 11-11-2022, 06:08 PM



Users browsing this thread: 1 Guest(s)