Serious Memory Issues while loading Images

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
kingomar
Prole
Posts: 37
Joined: Mon Mar 17, 2014 8:01 pm

Serious Memory Issues while loading Images

Post by kingomar » Sun Apr 20, 2014 5:36 pm

Hello Everybody! Im partially new to Love2d and i almost finished my first game..
However, My game uses alot of Memory! and it's really slow to open.. like when i click on the .love file it causes my computer to freeze and takes more than 10 seconds to start! Moreover, what's even worse, it draw alot of Memory! Over 385k!
Untitled.png
Untitled.png (1.79 KiB) Viewed 3207 times
But i'm not surprised though, i'm loading more than 300 images in my game through love.load()
I tried to monitor where all the memory issues is coming from and discovered that the line:

Code: Select all

require "Laboratory"
is causing all the problems.. In that lua file im trying to load like almost 250 images and im not done yet.. i'm loading them without calling a function, just by defining table.. like this as an example:

Code: Select all

Step1[1] = love.graphics.newImage("Resources/Dilution/Step1/1.png")
Step1[2] = love.graphics.newImage("Resources/Dilution/Step1/2.png")
Step1[3] = love.graphics.newImage("Resources/Dilution/Step1/3.png")
Step1[4] = love.graphics.newImage("Resources/Dilution/Step1/4.png")
Step1[5] = love.graphics.newImage("Resources/Dilution/Step1/5.png")
Step1[6] = love.graphics.newImage("Resources/Dilution/Step1/6.png")
Step1[7] = love.graphics.newImage("Resources/Dilution/Step1/7.png")
Step1[8] = love.graphics.newImage("Resources/Dilution/Step1/8.png")
Step1[9] = love.graphics.newImage("Resources/Dilution/Step1/9.png")
Step1[10] = love.graphics.newImage("Resources/Dilution/Step1/10.png")
Step1[11] = love.graphics.newImage("Resources/Dilution/Step1/11.png")
Step1[12] = love.graphics.newImage("Resources/Dilution/Step1/12.png")
Almost 300 line like that... Hehe...
I Considered using Kikito Library(This guy is epic though) loader.. i thought it might help.. but i prefered making sure that it will help before wasting time using it..

What's even worse i'm only half done of adding images and there's still sounds...
I don't want to add love files because i want it to still exclusive until i release it soon enough..
What's the best way to fix this major problem? And is there any way i can lower the memory consumption?

Thanks Guys! You're Epic!

UPDATE: https://www.dropbox.com/s/inlqlae5csogrsz/DEMO.love Love File
Last edited by kingomar on Sun Apr 20, 2014 8:09 pm, edited 2 times in total.
Check out my game:
- Youtube Video : http://goo.gl/91x6dT
- Download Link : http://goo.gl/6llhmp

User avatar
Jasoco
Inner party member
Posts: 3650
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Serious Memory Issues while loading Images

Post by Jasoco » Sun Apr 20, 2014 5:43 pm

How big are these images? If they're huge then of course they'll take a lot of memory.

Also, that entire block of code can be replaced with this simple loop in case you didn't know:

Code: Select all

Step1 = {}
for i = 1, 300 do
    Step1[i] = love.graphics.newImage("Resources/Dilution/Step1/" .. i ..  ".png")
end
Change 300 to however many images you have. And if you have more than one step, I suggest making it a multi-dimentional table like so instead:

Code: Select all

Step = {}
for s = 1, numberOfSteps do
    Step[s] = {}
    for i = 1, 300 do
        Step[s][i] = love.graphics.newImage("Resources/Dilution/Step" .. s .. "/" .. i ..  ".png")
    end
end
But really, as long as those images aren't huge (What are they? Sprites) then it's better to use one big sheet of images and split it into quads instead of individual images. But if they're supposed to be slides for a sort of video like animation then man, that's a lot of slides.

I mean what exactly are these images?

User avatar
kingomar
Prole
Posts: 37
Joined: Mon Mar 17, 2014 8:01 pm

Re: Serious Memory Issues while loading Images

Post by kingomar » Sun Apr 20, 2014 6:18 pm

Sir i tried your suggestion and the Memory usage got way higher! reached 670k and then love2d gave me the error : "Out Of Memory"

I'm trying to load these images:
http://postimg.org/image/nieq0ioh1/

Each frame is extracted and is getting loaded in my game.. every image weights like 10kb in size..
Any Solution?
Check out my game:
- Youtube Video : http://goo.gl/91x6dT
- Download Link : http://goo.gl/6llhmp

User avatar
MadByte
Party member
Posts: 495
Joined: Fri May 03, 2013 6:42 pm
Location: Germany

Re: Serious Memory Issues while loading Images

Post by MadByte » Sun Apr 20, 2014 6:52 pm

Please upload your *.love, maybe we can find an issue here

User avatar
kingomar
Prole
Posts: 37
Joined: Mon Mar 17, 2014 8:01 pm

Re: Serious Memory Issues while loading Images

Post by kingomar » Sun Apr 20, 2014 8:09 pm

Updated with the link.
Check out my game:
- Youtube Video : http://goo.gl/91x6dT
- Download Link : http://goo.gl/6llhmp

User avatar
kingomar
Prole
Posts: 37
Joined: Mon Mar 17, 2014 8:01 pm

Re: Serious Memory Issues while loading Images

Post by kingomar » Mon Apr 21, 2014 6:37 am

Is the library loader is a nice solution?
Or can i require a .lua file when needed?? like when i need to access the GameState where it requires these images to be loaded..
Check out my game:
- Youtube Video : http://goo.gl/91x6dT
- Download Link : http://goo.gl/6llhmp

User avatar
headchant
Party member
Posts: 105
Joined: Fri Sep 03, 2010 12:39 pm
Contact:

Re: Serious Memory Issues while loading Images

Post by headchant » Mon Apr 21, 2014 10:53 am

This project is way too big to analyse without proper indentation. Please indent your code and reupload and you might get better help.

User avatar
SneakySnake
Citizen
Posts: 94
Joined: Fri May 31, 2013 2:01 pm
Contact:

Re: Serious Memory Issues while loading Images

Post by SneakySnake » Mon Apr 21, 2014 12:44 pm

There is only so much you can do about loading so many - quite large - images at once.
You could show a loading screen while loading the assets.
If the memory usage is a problem, you should try to only load the resources that are necessary at a time, instead of loading everything at the beginning.

User avatar
kingomar
Prole
Posts: 37
Joined: Mon Mar 17, 2014 8:01 pm

Re: Serious Memory Issues while loading Images

Post by kingomar » Tue Apr 22, 2014 10:45 am

I used loader library and it works like a charm.. But still got the same Memory usage... However i was wondering.. If i destroy the tables where my images are contained.. Will the high usage of memory will still occur? Thanks
Check out my game:
- Youtube Video : http://goo.gl/91x6dT
- Download Link : http://goo.gl/6llhmp

bizziboi
Citizen
Posts: 55
Joined: Sat Apr 16, 2011 9:24 am

Re: Serious Memory Issues while loading Images

Post by bizziboi » Thu Apr 24, 2014 8:12 pm

If you convert the images to DDS they will be a bit faster to load and use less memory - you could give that a shot.

Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests