memory issue
Moderators: Shine, Insert_witty_name
-
- Posts: 123
- Joined: Mon Oct 03, 2005 4:25 am
- Location: Netherlands
memory issue
I've been working secretly on a 2D scrolling platform game inspired by splinter cell, of wich I will release a testing version soon. This may well be one of the largest luaplayer projects I know of. But, I've got a problem: memory. It runs out. I try to load as much as I can at the program's startup, so that I don't have to reload a lot. This involves loading roughly 60 png's and 3 small wav's. After all this is done, I start my level editor (yes,that's included too(-: ) wich gives me a memory indication: 6 megs. This gradually decreases when loading levels. Luckily, I've managed to let the fileselector load nothing when it's starting, wich would mean I would crash on saving a level in case of low mem.
But is loading everythin at startup the right approach? Or do you have other tips? Please let me know. I'm using 0.16, so it doesn't load modules or stuff like that (wich is good for mem usage)
But is loading everythin at startup the right approach? Or do you have other tips? Please let me know. I'm using 0.16, so it doesn't load modules or stuff like that (wich is good for mem usage)
Behold! The Underminer got hold of a PSP
-
- Posts: 123
- Joined: Mon Oct 03, 2005 4:25 am
- Location: Netherlands
can't get it done
Yes Romero, that's my plan, but I can't get it to work. look at this:
When I call my level editor with Unload(3) (all items in 3 are not neccesary for the editor) at the first line, it still says 2mb free. Almost worse than I started with... Pretty depressing right here...
Code: Select all
--some other stuff
elseif item == 3 then
animations={Image.load("./animation/running_right.png"),5,Image.load("./animation/running_left.png"),5,Image.load("./animation/sam_crouchwalk_right.png"),8,Image.load("./animation/sam_crouchwalk_left.png"),8 --1 to 8
,Image.load("./animation/sam_gunreach_right.png"),6,Image.load("./animation/sam_gunreach_left.png"),6,Image.load("./animation/sam_gunwalk_right.png"),8,Image.load("./animation/sam_gunwalk_left.png"),8 -- 9 to 16
,Image.load("./animation/sam_elbow_right.png"),6,Image.load("./animation/sam_elbow_left.png"),6,Image.load("./animation/sam_shoot_right.png"),6,Image.load("./animation/sam_shoot_left.png"),6 -- 17 to 24
,Image.load("./animation/ClimbOnBlock_right.png"),4,Image.load("./animation/ClimbOnBlock_left.png"),4,Image.load("./animation/ClimbOn2Block_right.png"),7,Image.load("./animation/ClimbOn2Block_left.png"),7 --25 to 32
,Image.load("./animation/jump_right.png"),7,Image.load("./animation/jump_right.png"),7,Image.load("./animation/falling_right.png"),3,Image.load("./animation/falling_left.png"),3,Image.load("./animation/Ladder_up.png"),7 --33 to 42
,Image.load("./animation/Jump_up_right.png"),3,Image.load("./animation/Jump_up_left.png"),3,Image.load("./animation/TurnToladder_right.png"),5,Image.load("./animation/TurnToladder_left.png"),5,Image.load("./animation/shimny_right.png"),7,Image.load("./animation/shimny_left.png"),7--43-54
,Image.load("./animation/sam_diying_right.png"),3,Image.load("./animation/sam_diying_left.png"),3} -- 55-58
BufferX,BufferY = Image.createEmpty(64, 320),Image.createEmpty(480, 64)
DeBrief = Image.load("./animation/debriefing.png")
Failed = Image.load("./animation/failed.png")
StatsBar = Image.load("./animation/statsbar.png")
bulletR,bulletL = Image.load("./animation/bulletR.png"),Image.load("./animation/bulletL.png")
pangR,pangL = Image.load("./animation/pangR.png"),Image.load("./animation/pangL.png")
Loaded[3] = 1
end
Code: Select all
function Unload(item)
if item == 3 then
UnloadTable = {animations,BufferX,BufferY,DeBrief,Failed,StatsBar,bulletR,bulletL,pangR,pangL}
end
for i,var in ipairs(UnloadTable) do var = nil end
end
Behold! The Underminer got hold of a PSP
Try organizing your tables a little bit better. It seems like your tables.. should be setup simpler.
Does not remove all instances of the table, Unless Unload(item) returns a new table which you use to write over the existing table. Thus redefining the table and clearing up the existing memory.
Your table configuration also seems a little bit on the weak side.
Try useing nested tables for animations. Then you can search for the object by ID, or use it in an array.
Example
There are some options for you to use. Please define all instances of the variable to nil and make shure there is no copys of the tables anywhere else.
Code: Select all
function Unload(item)
if item == 3 then
UnloadTable = {animations,BufferX,BufferY,DeBrief,Failed,StatsBar,bulletR,bulletL,pangR,pangL}
end
for i,var in ipairs(UnloadTable) do
var = nil
end
end
Your table configuration also seems a little bit on the weak side.
Try useing nested tables for animations. Then you can search for the object by ID, or use it in an array.
Example
Code: Select all
Animations = {
{ "ID1", Image.load("./animation/sam_crouchwalk_right.png"), DisplayTime },
{ "ID2", Image.load("./animation/sam_crouchwalk_right.png"), DisplayTime },
{ "ID3", Image.load("./animation/sam_crouchwalk_right.png"), DisplayTime },
{ "ID4", Image.load("./animation/sam_crouchwalk_right.png"), DisplayTime },
{ "ID5", Image.load("./animation/sam_crouchwalk_right.png"), DisplayTime },
{ "ID6", Image.load("./animation/sam_crouchwalk_right.png"), DisplayTime },
{ "ID7", Image.load("./animation/sam_crouchwalk_right.png"), DisplayTime },
{ "ID8", Image.load("./animation/sam_crouchwalk_right.png"), DisplayTime },
}
-
- Posts: 123
- Joined: Mon Oct 03, 2005 4:25 am
- Location: Netherlands
Thanks for your quick reply.
when I'm having a problem that I can't solve after 2 days, I like to make some test scripts to clear my mind. Look at this:
The result is:
19456 -- the memory left after starting luaplayer
15360 -- memory left after loading the images, wich apparantly require 3mb
15360 -- memory available after setting animations to nil, no memory is cleaned
15360 --memory available after redifining table animations, overwriting it like you suggested. Doesn't help either
PS. This script stands alone and thus I can be sure there are no references to it.
PS 2:
gives the same result
when I'm having a problem that I can't solve after 2 days, I like to make some test scripts to clear my mind. Look at this:
Code: Select all
print(System.getFreeMemory() / 1024)
animations={Image.load("./animation/running_right.png"),5,Image.load("./animation/running_left.png"),5,Image.load("./animation/sam_crouchwalk_right.png"),8,Image.load("./animation/sam_crouchwalk_left.png"),8 --1 to 8
,Image.load("./animation/sam_gunreach_right.png"),6,Image.load("./animation/sam_gunreach_left.png"),6,Image.load("./animation/sam_gunwalk_right.png"),8,Image.load("./animation/sam_gunwalk_left.png"),8 -- 9 to 16
,Image.load("./animation/sam_elbow_right.png"),6,Image.load("./animation/sam_elbow_left.png"),6,Image.load("./animation/sam_shoot_right.png"),6,Image.load("./animation/sam_shoot_left.png"),6 -- 17 to 24
,Image.load("./animation/ClimbOnBlock_right.png"),4,Image.load("./animation/ClimbOnBlock_left.png"),4,Image.load("./animation/ClimbOn2Block_right.png"),7,Image.load("./animation/ClimbOn2Block_left.png"),7 --25 to 32
,Image.load("./animation/jump_right.png"),7,Image.load("./animation/jump_right.png"),7,Image.load("./animation/falling_right.png"),3,Image.load("./animation/falling_left.png"),3,Image.load("./animation/Ladder_up.png"),7 --33 to 42
,Image.load("./animation/Jump_up_right.png"),3,Image.load("./animation/Jump_up_left.png"),3,Image.load("./animation/TurnToladder_right.png"),5,Image.load("./animation/TurnToladder_left.png"),5,Image.load("./animation/shimny_right.png"),7,Image.load("./animation/shimny_left.png"),7--43-54
,Image.load("./animation/sam_diying_right.png"),3,Image.load("./animation/sam_diying_left.png"),3} -- 55-58
print(System.getFreeMemory() / 1024)
animations = nil
print(System.getFreeMemory() / 1024)
animations = {}
print(System.getFreeMemory() / 1024)
19456 -- the memory left after starting luaplayer
15360 -- memory left after loading the images, wich apparantly require 3mb
15360 -- memory available after setting animations to nil, no memory is cleaned
15360 --memory available after redifining table animations, overwriting it like you suggested. Doesn't help either
PS. This script stands alone and thus I can be sure there are no references to it.
PS 2:
Code: Select all
for i,item in ipairs(animations) do
item = nil
end
print(System.getFreeMemory() / 1024)
Behold! The Underminer got hold of a PSP
-
- Posts: 376
- Joined: Wed May 10, 2006 11:31 pm
Try adding a call to the garbage collection function, I think this is right but I don't use Lua, sorry:
Code: Select all
collectgarbage()
-
- Posts: 123
- Joined: Mon Oct 03, 2005 4:25 am
- Location: Netherlands
There was a problem in earlier version of Lua Player. With 0.20 and this code, saved as script.lua:the underminer wrote:that command exists in lua, but I had no results again...
Code: Select all
white = Color.new(255, 255, 255)
screen:print(0, 0, System.getFreeMemory() / 1024, white)
test1 = Image.load("Applications/Snake/desert.png")
test2 = Image.load("Applications/Snake/desert.png")
test3 = Image.load("Applications/Snake/desert.png")
screen:print(0, 8, System.getFreeMemory() / 1024, white)
test1 = nil
test2 = nil
test3 = nil
collectgarbage()
screen:print(0, 16, System.getFreeMemory() / 1024, white)
while not Controls.read():start() do
screen.waitVblankStart()
screen.flip()
end
So the right solution would be first to fix the memory problem with loading modules (maybe Oobles has any ideas about it) and then the modules loader for firmware > 1.5.
-
- Posts: 123
- Joined: Mon Oct 03, 2005 4:25 am
- Location: Netherlands
Thanks for your reply Shine, but the big downside to this good news is that 020 has a whooping 10mb less memory. Still I tried, but when loading my first level I got this can't create image error (Because it ran outta memory)
I'll just think about what to do next. Maybe I can alter my code so that it can cope with 9 megs, but I don't think Ill manage to do so.
Thanks again
I'll just think about what to do next. Maybe I can alter my code so that it can cope with 9 megs, but I don't think Ill manage to do so.
Thanks again
Behold! The Underminer got hold of a PSP
Yes, that's what I mean with "the memory problem". Oobles, who implemented the module support, wrote me an eMail that it could be a limitation of the PSPSDK, because you have to specifiy how much memory each module needs at compile time. But currently I don't have time to fix it, maybe ask Oobles.the underminer wrote:Thanks for your reply Shine, but the big downside to this good news is that 020 has a whooping 10mb less memory.
-
- Posts: 123
- Joined: Mon Oct 03, 2005 4:25 am
- Location: Netherlands
Yup the Ogg/Mp3 one is non-module. It was originally intended to be used with the original 2.00 tiff exploit (since that is what i was using) with luaplayer .20, since at the time you could only use luaplayer .16 on 2.00.
The Over/Underclocking was removed; The function(s) itself were not harmful to the psp in any way, its just that if one user decides to:
Even calling any one of the system over/under clocking functions in a while true do loop could be harmful. (Setting your psp to 333 mhz every loop... not good)
Stick with IRShell, its a lot safer!
The Over/Underclocking was removed; The function(s) itself were not harmful to the psp in any way, its just that if one user decides to:
Code: Select all
function overloadpsp()
l = 1
System.setClockSpeed(l)
l = l + 1
end
Stick with IRShell, its a lot safer!
-
- Posts: 4
- Joined: Mon Feb 06, 2006 9:13 am
-
- Posts: 123
- Joined: Mon Oct 03, 2005 4:25 am
- Location: Netherlands
You can never use screen to store an image in!!Mechanical wrote:Hi ;)
I have a noob question. How to unload png from memory?
screen = Image.load("screen.png")
screen = nil
??
screen is reserved for what you see on the screen. To show an image on the screen you do this:
Duck = Image.load("duck.png")
screen:clear() -- removes everything that was on the screen buffer
screen:blit(0,0,Duck)
screen.flip() -- this draws on the physical screen what is in the screen buffer. Anything you change in the buffer'screen' will only be visible after you do screen.flip()
Behold! The Underminer got hold of a PSP
-
- Posts: 4
- Joined: Mon Feb 06, 2006 9:13 am