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

2020/3/19

Error in GifImage class

108089 108089

2020/3/19

#
Hi, while working on a game with a Gif in the background and one actor that is a Gif the program doesnt compile and I get the following lines to appear red in my terminal window: java.lang.OutOfMemoryError: Java heap space ... at GifImage.loadImages(GifImage.java:150) at GifImage.<init>(GifImage.java:66) at weg.<init>(weg.java:13) ... Does anyone what can causes this and how to fix this?
danpost danpost

2020/3/20

#
Please show your World subclass codes.
108089 108089

2020/3/20

#
This is my code. I now just have one actor that will spawn in and just in lane A. But in the end it is my goal to randomly generate a object in each lane (A, B and C) based on the randomly generated integers A, B and C.
import greenfoot.*;

/**
 * Write a description of class weg here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */

public class weg extends World
{

    GifImage background = new GifImage("achtergrond.gif");
    private int Timer = 0;
    /**
     * Constructor for objects of class weg.
     * 
     */
    public weg()
    {         
        super(510, 510, 1); 
        addObject(new man(), 255, 370);  
        setPaintOrder(man.class, auto.class, blok.class);
        
    }
    
    private int A = 0;
    private int B = 0;
    private int C = 0;
    
    public void act()
    { 
        setBackground( background.getCurrentImage() );
        if (Timer <150) {
            Timer++;
        }
        else {
            Timer = 0;
            A = Greenfoot.getRandomNumber(3);
            B = Greenfoot.getRandomNumber(3);
            C = Greenfoot.getRandomNumber(3);
               
            if (A == 2) {
                addObject(new auto(), 250, 180);
                
            }
            
            //String AA = Integer.toString(A);
            //showText(AA, 255, 255);
            
        }
        
        
    }
}
108089 108089

2020/3/20

#
I forgot to mention that the error doesn't Always show up. It does show up once every few times I compile, even if I don't change anything. If I than close greenfoot en open my project again and than it works just fine. This might be important.
danpost danpost

2020/3/20

#
I have a feeling it is your background gif images that are using up your memory. What is the actual size of each image in the gif set?
108089 108089

2020/3/25

#
The background image is 4,53 MB and the actor is only 67 kB so I think that it is indeed the background image that causes the problem. Is there a way to fix this?
danpost danpost

2020/3/25

#
108089 wrote...
The background image is 4,53 MB and the actor is only 67 kB so I think that it is indeed the background image that causes the problem. Is there a way to fix this?
I really cannot say. How many images are in the gif and what are the dimensions of each image?
108089 108089

2020/3/26

#
I have just comprimized the gif and now it is only about 1 MB, but I stil have the same issue. I have no idea how many images are in the Gif. Besides that my greenfoot dit kind of crash. After restarting greenfoot it I am unable to change anything. See the image for a print screen. PrtScr By the way thanks for al the help untill now, I hope you can help me out once again!
danpost danpost

2020/3/26

#
Put print screen to an image sharing site (like imgur). I, for one, do not open anything that could potentially be harmful to my computer.
danpost danpost

2020/3/26

#
Can you open other scenarios and change them?
108089 108089

2020/4/13

#
Thanks for helping, i have worked around the problem by chosing a different background. Sorry for not replying for so long but i just forgot about it.
You need to login to post a reply.