Page 1 of 1

font data not being freed

Posted: Fri Sep 14, 2012 17:33
by gjaegy
Hi,

I am trying to catch a memory leak, basically, my FreeTypeFont::d_fontData is not destroyed, and I don't know why (all the other resources allocated by CEGUI are being freed up).

I am using the latest version from the source repository.

I am instancing my GUI from Lua (see whole script below).

The d_fontData is being allocated in FreeTypeFont:updateFon():

Code: Select all

    System::getSingleton().getResourceProvider()->loadRawDataContainer(
        d_filename, d_fontData, d_resourceGroup.empty() ?
            getDefaultResourceGroup() : d_resourceGroup);


Shall I manually delete it ? That doesn't sound right, as I am not instancing it by myself... What am I doing wrong (or actually not doing) ?

Thanks,

Below the script I am using:

Code: Select all

local oScriptInterface = imScriptInterface.g_TheScriptInterface;
local oScene = oScriptInterface:GetActiveScene();

local oSimManager = imSimManager.g_TheSimManager;   
local oDrivingSim = oSimManager:GetDrivingSimulator();

local bFirstUpdate = 1;

-------------------------------------------------------------------------------------------------

function updateHandler(args)
    local root = CEGUI.System:getSingleton():getDefaultGUIContext():getRootWindow()

   local sBrakeForceText = oDrivingSim:ScriptGetBrakeForcePerSecSqPerKg();
   root:getChild("root/ADTTuningWindow/EditboxBrakeForceCurrent"):setText(sBrakeForceText)

   local sFrictionText = oDrivingSim:ScriptGetFrictionRatio();
   root:getChild("root/ADTTuningWindow/EditboxFrictionCurrent"):setText(sFrictionText)
   
   if (bFirstUpdate == 1) then
      root:getChild("root/ADTTuningWindow/EditboxBrakeForceNew"):setText(sBrakeForceText)
      root:getChild("root/ADTTuningWindow/EditboxFrictionNew"):setText(sFrictionText)
      bFirstUpdate = 0
   end
end

-------------------------------------------------------------------------------------------------

-----------------------------------------
-- Script Entry Point
-----------------------------------------
local guiSystem = CEGUI.System:getSingleton()
local schemeMgr = CEGUI.SchemeManager:getSingleton()
local winMgr = CEGUI.WindowManager:getSingleton()

-- load our scheme
local scheme = schemeMgr:createFromFile("AlfiskoSkin.scheme");
-- load our window layout
local window = winMgr:loadLayoutFromFile("ADTTuning.layout")
-- set the layout as the root
local root = CEGUI.System:getSingleton():getDefaultGUIContext():getRootWindow()
root:addChild(window);

-- set default mouse cursor
guiSystem:getDefaultGUIContext():getMouseCursor():setDefaultImage("AlfiskoSkin/MouseArrow")

-- subscribe required events
root:getChild("root/ADTTuningWindow"):subscribeEvent("Updated", "updateHandler")

Re: font data not being freed

Posted: Sat Sep 15, 2012 09:19
by Kulik
I see it being freed in updateFont. It could be some bug specific to your scenario, please do some more digging :-)

Re: font data not being freed

Posted: Thu Sep 20, 2012 08:58
by gjaegy
It is being freed *before* it's being loaded, to make sure all objects allocated before the loading are being destroyed:

Code: Select all

void FreeTypeFont::updateFont()
{
    free();

    System::getSingleton().getResourceProvider()->loadRawDataContainer(
        d_filename, d_fontData, d_resourceGroup.empty() ?
            getDefaultResourceGroup() : d_resourceGroup);


However, it's not being freed afterthat...

I have managed to solve the issue by calling the following clean up code at application exit:

Code: Select all

FontManager::getSingleton().destroyAll();


Problem solved :)