Jump to content

Fonts loading/deleting over and over again


Rick
 Share

Recommended Posts

I have a script where I load a new font in Start(). In PostRender() it saves off the original font, sets the font to the one loaded in Start(), draws text, then sets the font back to original. However in the output window I see non stop Deleting Font...Loading Font.. over and over again. Why would it be doing that when all I'm doing is switching between fonts?

 

 

local font = context:GetFont()

-- self.font is the font I load in Start()
context:SetFont(self.font)
context:SetBlendMode(Blend.Alpha)

context:DrawText(self.msg, pos.x, pos.y)

context:SetBlendMode(Blend.Solid)
context:SetFont(font)
Link to comment
Share on other sites

My guess is, since I was setting the current font to my own font that I loaded, it was releasing the default font, which would cause it to get deleted, even though I pulled out the default font and stored it in a variable before I did this. The font system didn't know I did this. So by using AddRef() to the default font I stored in a local variable, it would keep it alive.

 

I changed it to the following and it worked. Notice the AddRef() and Release()

 

local font = context:GetFont()

 

-- self.font is the font I load in Start()

font:AddRef()

context:SetFont(self.font)

context:SetBlendMode(Blend.Alpha)

 

context:DrawText(self.msg, pos.x, pos.y)

 

context:SetBlendMode(Blend.Solid)

context:SetFont(font)

font:Release()

  • Upvote 1
Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...