This site requires JavaScript, please enable it in your browser!
Greenfoot back
HardToFindAName
HardToFindAName wrote ...

2017/2/10

Greenfoot Images Size

HardToFindAName HardToFindAName

2017/2/10

#
Hello there! I am working on a project related to a contest, what I am basically trying is to make a form of 2016 "election game", won't go into the details. The point is, I've bascially created over 50 objects with all 50 states, arranged them, and now I'm trying to set up the scene. I have 3 pictures for each state, one for the neutral state, one for the democratic won state and one for the republican won state. So I thought I'd set up some 3 new GreenfootImages, but as I've started working and progressing, I came across this error message (which is actually quite a long message, I won't post it all here). Resuming, it's this phrase java.lang.OutOfMemoryError: Java heap space that stays there like a ghost haunting XD. I mean, it's not preventing me from continuing, it just pops up once when I declare a new private GreenfootImage and stays there. I think I've declared close or maybe 30 new GreenfootImages. The error raised some questions, so searching for it I found out that it's not actually good to use a big number of images declared as GreenfootImages. The point is, those imagese aren't big in size, they are small. 156 files in the images folder are occupying 1,5 MB of data, basically 10 KB per image. The error hasn't yet prevented me from continuing, again, but I just fear that when I get to the last state everything crashes or it becomes really laggy and I don't have time for that. Should I program it not as a GreenfootImage but specify the path directly? Some other details: The project is going to be quite large in my opinion, basically, 50 objects for each state, then a couple of different worlds. The main idea is that a player starts the game, chooses one of the candidates (Clinton vs Trump) and campaigns in the battleground states. How does it campaign? Well, I'm thinking that when a player selects a state to campaign it, there will be something like a notice popping out where he chooses one out of four options, four quotes of that respective candidate: "We're gonna build a wall" ; "Education should be our priority" or whatever. When he does, the GIF Image of the candidate will pop out and I'll play the sound simultaneously (I think that's possible). A timer will go in the background, and when the election day comes, the results will be shown as projections on TV (the states would change one after another (I think that's possible, right? There was a method, I need to find it)). Perhaps a comparison between his results and the actual results will also take place. And how are the results going to be decided? By abusing the random method, trying to be as realistic as possible and using some factors (the fact that the person campaigned in a state would likely increase his chances). So, an honest opinion, how large is it? Is it too large to finish until sunday if I work in full mode with a classmate? Is it possible (I mean, it won't turn out to be very laggy or crashing or things like that)? I think I've buzzled y'all till now. I'd love if someone could answer all my questions, but the GreenfootImages are the priority XD, so can I set up 150 new GreenfootImages considering they are pretty small? (1,5 MBs representing 150 images). Thank you in advance! Paul
valdes valdes

2017/2/11

#
Without the code is difficult to know the error. Check where are you declaring those GreenfootImages. It should be in the constructor of the world or as static variables. If it is inside an act() method or in any method called by act(), then you are creating an infinite loop and running out of memory.
danpost danpost

2017/2/11

#
The problem is not the amount of storage memory that is being taken up by the image files -- it is the amount of working memory for the project. You are probably creating all the images at the beginning and keeping them as GreenfootImages throughout the running of the project. I will throw around a couple of ideas. Consider creating them (the images) only when needed and not keeping references to them once their on-screen time is done. Using an array in your world class to contain all the necessary data on the states and using a single State object with changeable data would also help. You can send it a packet of state information and it can work with that states data, creating the images needed for that particular state on the fly.
You need to login to post a reply.