Rick Posted July 22, 2013 Posted July 22, 2013 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) Quote
Josh Posted July 22, 2013 Posted July 22, 2013 Call font->AddRef() once to prevent the font from being deleted automatically. Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Rick Posted July 22, 2013 Author Posted July 22, 2013 That worked thanks! I have to remember that. Quote
YouGroove Posted July 22, 2013 Posted July 22, 2013 @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 ? Quote Stop toying and make games
Rick Posted July 22, 2013 Author Posted July 22, 2013 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() 1 Quote
Flexman Posted August 1, 2013 Posted August 1, 2013 Not being negative here...B U T first thing I did was was check the documentation after reading this. Please add to official documentation. Quote 6600 2.4G / GTX 460 280.26 / 4GB Windows 7 Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT Tricubic Studios Ltd. ~ Combat Helo
YouGroove Posted August 1, 2013 Posted August 1, 2013 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 ? Quote Stop toying and make games
Rick Posted August 1, 2013 Author Posted August 1, 2013 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. Quote
Recommended Posts
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.