Jump to content

Recommended Posts

Posted

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)
Posted

Call font->AddRef() once to prevent the font from being deleted automatically.

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

@Rick what is the problem , if it works ?

( I don't know if i'll remember to call the AddRef() )

Perhaps we should have 2 functions : loadFont() and loadRefFont() instead of going into obscure programmer code ?

Stop toying and make games

Posted

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
  • 2 weeks later...
Posted

I really agree a lot.

For long term : usefull stuff should go to official docs.

 

WE SHOULD HAVE SOME OFFICIAL PUBLIC WIKI for all that code tips.

 

Why LE3 don't have that and only forums ?

Stop toying and make games

Posted

I'm a little torn on this one because the whole AddRef()/Release() applies to every LE entity and it's not font specific. This is just me being new to the AddRef()/Release() usage.

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.

×
×
  • Create New...