Jump to content

memory leak when sending a string to the load function


DooMAGE
 Share

Recommended Posts

Hello guys,

 

I am working on a loading screen, and when I pass a string to the load function call my loading screen the video memory jumps to 300mb+ to 800mb+ blink.png

 

Here my code:

 

-- world creation here

function LoadingScreen()
context:SetBlendMode(Blend.Alpha)
local loadingFont = Font:Load("Fonts/arial.ttf",42)
context:SetFont(loadingFont)
local loadingText = "L O A D I N G . . ."
local x = (window:GetWidth() / 2) - (loadingFont:GetTextWidth(loadingText) / 2)
local y = (window:GetHeight() / 2) - (loadingFont:GetHeight() / 2)
-- Fill screen with black
context:SetColor(0, 0, 0)
context:DrawRect(0, 0, window:GetWidth(), window:GetHeight())
-- Draw "Loading" text
context:SetColor(1, 1, 1)
context:DrawText(loadingText, x, y)

context:Sync(false)
end

LoadingScreen()

-- map loading here

-- inside the main loop
if Map:Load("Maps/"..changemapname..".map", "LoadingScreen")==false then return end
-- inside the main loop

 

I did something wrong?

My Leadwerks games!

https://ragingmages.itch.io/

Link to comment
Share on other sites

A leak would imply its continually increasing. The problem is with what you are doing with the hook.

 

hookname: script function name that will be called for each loaded entity in the scene.

 

You are loading the font every time an entity is loaded from your map.

 

Just call the loading screen function separately (and one time) if the map is changed then perform Map:Load().

 

... --in the main loops check for the changemapname

...

LoadingScreen()

if Map:Load("Maps/"..changemapname..".map")==false then return end

...

...

  • Upvote 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Also, just load the "loading font' once as well.

 

font = context:GetFont()

loadingFont = Font:Load("Fonts/arial.ttf",42)

loadingText = "L O A D I N G . . ."

 

function LoadingScreen()

context:SetBlendMode(Blend.Alpha)

context:SetFont(loadingFont)

local x = (window:GetWidth() / 2) - (loadingFont:GetTextWidth(loadingText) / 2)

local y = (window:GetHeight() / 2) - (loadingFont:GetHeight() / 2)

-- Fill screen with black

context:SetColor(0, 0, 0)

context:DrawRect(0, 0, window:GetWidth(), window:GetHeight())

-- Draw "Loading" text

context:SetColor(1, 1, 1)

context:DrawText(loadingText, x, y)

context:SetFont(font)

context:Sync(false)

end

 

LoadingScreen()

When I do this and what I showed above for changing maps, I get the same memory usage each time I load the same map instead of it increasing each load.

 

EDIT --Actually just load the font separately and one time like shown above and you can still keep the hook function in the Map:Load(). But since you are just drawing a static text/image there's no reason to do this as there is no reason to update per entity being loaded. If you were doing some kind of progress bar or dynamic text, then you would want to use the hook option.

  • Upvote 1

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

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...