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

2018/5/3

java.lang.OutOfMemoryError: Java heap space

Lavenger Lavenger

2018/5/3

#
I have searched many posts about this problem(in greenfoor.org and sstackoverflow.com) and most of the time when this comes out, it means that either i have a memory leakage or my scenario uses way too much heap space. I think that my problem here is that i have a memory leakage because it starts out fine but if i played too many Minigames(or if i reset the scenario), the error pops up. But the question is: how do i stop this memory leakage? Situation1: I was playing my game halfway and decided to tweak some things inside of the game(this happened quite long ago so i dont quite remember what did i do for that to happen) and when i reset the game, the error popped out. The error pointed out to the GifImage class Situation2 I was test running my game for a few minutes and when i played the minigame too many times, the error pops up The error pointed out to the PIP class these are my world class codes: Main game world class code:
import greenfoot.*;
public class MyWorld extends World
{
    // fields usually (by convention) go first
    
    //For GIF background stuff
    GifImage gifImg = new GifImage("Umaru.gif");
    public int getHeight = 552, getWidth = 1200 ;
    
    //For Timing stuff
    private Actor GameTimeDisplay = new SimpleActor(), Cooldown = new SimpleActor(), PCBuffTimeDisplay = new SimpleActor(), CCBuffTimeDisplay = new SimpleActor(), BRABuffTimeDisplay = new SimpleActor();
    private int frames, Cframes = (3+Greenfoot.getRandomNumber(5))*55, PCBframes = 5*55, CCBframes = 5*55, BRABframes = 5*55;
    
    //For Yen stuff
    public float AYen; //precise
    public int DYen; //rounded
    public Yen YenDisplay = new Yen();
    
    //For Buttons stuff
    public Actor MKButton = new SimpleActor(), HButton = new SimpleActor(), BButton = new SimpleActor(), AButton = new SimpleActor(), SButton = new SimpleActor(), KButton = new SimpleActor(), EButton = new SimpleActor(), TButton = new SimpleActor(), PCButton = new SimpleActor(), CCButton = new SimpleActor(), BRAButton = new SimpleActor(), Buttons[] = {MKButton, HButton, BButton, AButton, SButton, KButton, EButton, TButton, PCButton, CCButton};
    private String ButtonImages[] = {"MKButton", "HButton", "BButton", "AButton", "SButton", "KButton", "EButton", "TButton", "button-blue", "button-blue"};
    private int ButtonsArraySize = Buttons.length;
    
    //For Menu Upgrade Panel stuff
    private int CharacterYenIncome;
    private String SelectedCharacter;
    public Actor UpgradeButton1 = new SimpleActor(),UpgradeButton5 = new SimpleActor(),UpgradeButton10 = new SimpleActor(), CharacterYenIncomeDisplay = new SimpleActor();
    public Actor MgrKanau = new MgrKanau(), Hikari = new Hikari(), Alex = new Alex(), Sylphynford = new Sylphynford(), Bomba = new Bomba(), Kirie = new Kirie(), Ebina = new Ebina(), Taihei = new Taihei();
    
    //For PIP stuff
    PIP pip;
    World minor;
    public Boolean setActiveState = false;
    Actor mouseActor; // holds the actor being dragged
    int mouseOffX, mouseOffY; // holds the offsets of mouse location from center of object being dragged
    // class constructors usually (by convention) go next
    
    //To construct MyWorld
    public MyWorld()
    {
        //For building the world window size
        super(1400, 675, 1);
        
        //For Yen stuff
        addObject(new Umaru(), 700, 338);
        adjustYen(0); // to initialize image
        addObject(YenDisplay, 1265, 50); // wherever
        
        //For updating the time display
        updateGameTimeDisplay();
        addObject(GameTimeDisplay, 1265, 20);
        
        //For triggering the minigame
        updateCooldownDisplay();
        addObject(Cooldown, 1265, 35);
        
        //For adding in the buttons to add the actors into the world
        for( int i = 0; i < ButtonsArraySize; i++)
        {
            Buttons[i].setImage(ButtonImages[i] + ".png"); Buttons[i].getImage().scale(70, 70); addObject(Buttons[i], 1212, (100 + (i*40)));
            i++;
            Buttons[i].setImage(ButtonImages[i] + ".png"); Buttons[i].getImage().scale(70, 70); addObject(Buttons[i], 1312, (100 + ((i-1)*40)));
        }
        BRAButton.setImage("button-blue.png"); BRAButton.getImage().scale(70, 70); addObject(BRAButton, 1262, 500);
        //Upgrade Panel UI
        //UpgradeButton1.setImage("Upgr1.png"); UpgradeButton1.getImage().scale(70, 70); addObject(UpgradeButton1, 1212, 620);
        //UpgradeButton5.setImage("Upgr5.png"); UpgradeButton5.getImage().scale(70, 70); addObject(UpgradeButton5, 1262, 620);
        //UpgradeButton10.setImage("Upgr10.png"); UpgradeButton10.getImage().scale(70, 70); addObject(UpgradeButton10, 1312, 620);
        CharacterYenIncomeDisplay.setImage(new GreenfootImage(" ", 20, Color.BLACK, new Color(0, 0, 0, 0)));addObject(CharacterYenIncomeDisplay, 1262, 570);
    }
    //For GIF background
    private void gifAnimation()
    {
        for (Object obj : gifImg.getImages()) ((GreenfootImage)obj).scale(getWidth(), getHeight());
        setBackground(gifImg.getCurrentImage());
    }
    // methods (by convention) go last
    
    //For executing all preccesses in MyWorld
    public void act()
    {
        //For GIF background
        gifAnimation();
        //Menu Stuff
        if(Greenfoot.mouseClicked(MKButton)){if(getObjects(MgrKanau.class).isEmpty()){if(AYen >= 100){AYen -= 100; addObject(MgrKanau, 600, 600); SelectedCharacter = "Manager Kanau Income: ";}else SelectedCharacter = "Character not bought";}else SelectedCharacter = "MgrKanau Income: ";}
        if(Greenfoot.mouseClicked(HButton)){if(getObjects(Hikari.class).isEmpty()){if(AYen >= 200){AYen -= 200; addObject(Hikari, 600, 600); SelectedCharacter = "Hikari Income: ";}else SelectedCharacter = "Character not bought";}else SelectedCharacter = "Hikari Income: ";}
        if(Greenfoot.mouseClicked(AButton)){if(getObjects(Alex.class).isEmpty()){if(AYen >= 400){AYen -= 400; addObject(Alex, 600, 600); SelectedCharacter = "Alex Income: ";}else SelectedCharacter = "Character not bought";}else SelectedCharacter = "Alex Income: ";}
        if(Greenfoot.mouseClicked(SButton)){if(getObjects(Sylphynford.class).isEmpty()){if(AYen >= 800){AYen -= 800; addObject(Sylphynford, 600, 600); SelectedCharacter = "Sylphynford Income: ";}else SelectedCharacter = "Character not bought";}else SelectedCharacter = "Sylphynford Income: ";}
        if(Greenfoot.mouseClicked(BButton)){if(getObjects(Bomba.class).isEmpty()){if(AYen >= 1600){AYen -= 1600; addObject(Bomba, 600, 600); SelectedCharacter = "Bomba Income: ";}else SelectedCharacter = "Character not bought";}else SelectedCharacter = "Bomba Income: ";}
        if(Greenfoot.mouseClicked(KButton)){if(getObjects(Kirie.class).isEmpty()){if(AYen >= 3200){AYen -= 3200; addObject(Kirie, 600, 600); SelectedCharacter = "Kirie Income: ";}else SelectedCharacter = "Character not bought";}else SelectedCharacter = "Kirie Income: ";}
        if(Greenfoot.mouseClicked(EButton)){if(getObjects(Ebina.class).isEmpty()){if(AYen >= 6400){AYen -= 6400; addObject(Ebina, 600, 600); SelectedCharacter = "Ebina Income: ";}else SelectedCharacter = "Character not bought";}else SelectedCharacter = "Ebina Income: ";}
        if(Greenfoot.mouseClicked(TButton)){if(getObjects(Taihei.class).isEmpty()){if(AYen >= 12800){AYen -= 12800; addObject(Taihei, 600, 600); SelectedCharacter = "Taihei Income: ";}else SelectedCharacter = "Character not bought";}else SelectedCharacter = "Taihei Income: ";}
        if(Greenfoot.mouseClicked(PCButton) && AYen >= 2000 && (getObjects(PChips.class).isEmpty())) {AYen -= 2000; addObject(new PChips(), 600, 600);}
        if(Greenfoot.mouseClicked(CCButton) && AYen >= 8000 && (getObjects(CCola.class).isEmpty())) {AYen -= 8000; addObject(new CCola(), 600, 600);}
        if(Greenfoot.mouseClicked(BRAButton) && AYen >= 36000 && (getObjects(BRAnime.class).isEmpty())) {AYen -= 36000; addObject(new BRAnime(), 600, 600);}
        //For updating the Timing stuff
        if ((++frames)%55 == 0) updateGameTimeDisplay();
        if ((--Cframes)%55 == 0) updateCooldownDisplay();
        if (!getObjects(PChips.class).isEmpty() && (--PCBframes)%55 ==0) updatePCBuffTimeDisplay();
        if (!getObjects(CCola.class).isEmpty() && (--CCBframes)%55 ==0) updateCCBuffTimeDisplay();
        if (!getObjects(BRAnime.class).isEmpty() && (--BRABframes)%55 ==0) updateBRABuffTimeDisplay();
        if (Cframes == 0)
        {
            Minigame();
            Cframes += ((3+Greenfoot.getRandomNumber(5))*55); //chooses a cooldown time between 3-7 minutes randomly     
        }
        if (CCBframes == 0) CCBframes += 3*55;
        if (PCBframes == 0) PCBframes += 3*55;
        if (BRABframes == 0) BRABframes += 3*55;
        // control dragging of PIP objects
        if (Greenfoot.mousePressed(null) && mouseActor == null)
        {
            MouseInfo mouse = Greenfoot.getMouseInfo();
            if (mouse.getActor() == null || mouse.getActor().getClass() != PIP.class) return;
            mouseActor = mouse.getActor();
            mouseOffX = mouseActor.getX()-mouse.getX();
            mouseOffY = mouseActor.getY()-mouse.getY();
            removeObject(mouseActor);
            addObject(mouseActor, mouse.getX()+mouseOffX, mouse.getY()+mouseOffY);
        }
        if (mouseActor != null && Greenfoot.mouseDragged(mouseActor))
        {
            MouseInfo mouse = Greenfoot.getMouseInfo();
            mouseActor.setLocation(mouse.getX()+mouseOffX, mouse.getY()+mouseOffY);
        }
        if (mouseActor != null && Greenfoot.mouseClicked(mouseActor)) mouseActor = null;
        //for removing ended Minigames
        if (pip != null && pip.getWorld() == this && minor.getObjects(null).isEmpty()) removeObject(pip);
    }
    //For Yen Display stuff
    public int getAccumulatedYen() {return DYen;}
    public void adjustYen(float adjustment)
    {
        AYen += adjustment;
        DYen = (int) AYen;
        YenDisplay.setImage(new GreenfootImage("Yen: "+DYen+"¥", 20, new Color(113, 50, 255, 255), new Color(0, 0, 0, 0)));
    }
    
    //Time Displays
    //Potato Chip Buff
    private void updatePCBuffTimeDisplay()
    {
        int Time = PCBframes/55;
        String minutes = "0"+(Time/60)/* string remaining minutes*/, seconds = "0"+(Time%60)/* string remaining seconds*/, mins = minutes.substring(minutes.length()-2)/* minutes output string*/, secs = seconds.substring(seconds.length()-2)/* seconds output string*/, TimeFormat = "Buff: "+mins+":"+secs;// Preview: Buff: 03:27
        PCBuffTimeDisplay.setImage(new GreenfootImage(TimeFormat, 20, new Color(100, 255, 100, 40) , new Color(0, 0, 0, 0)));
    }
    //Coca Cola Buff
    private void updateCCBuffTimeDisplay()
    {
        int Time = CCBframes/55;
        String minutes = "0"+(Time/60)/* string remaining minutes*/, seconds = "0"+(Time%60)/* string remaining seconds*/, mins = minutes.substring(minutes.length()-2)/* minutes output string*/, secs = seconds.substring(seconds.length()-2)/* seconds output string*/, TimeFormat = "Buff: "+mins+":"+secs;// Preview: Buff: 01:19
        CCBuffTimeDisplay.setImage(new GreenfootImage(TimeFormat, 20, new Color(100, 255, 100, 40) , new Color(0, 0, 0, 0)));
    }
    //Blu-Ray Anime Buff
    private void updateBRABuffTimeDisplay()
    {
        int Time = BRABframes/55;
        String minutes = "0"+(Time/60)/* string remaining minutes*/, seconds = "0"+(Time%60)/* string remaining seconds*/, mins = minutes.substring(minutes.length()-2)/* minutes output string*/, secs = seconds.substring(seconds.length()-2)/* seconds output string*/, TimeFormat = "Buff: "+mins+":"+secs;// Preview: Buff: 04:54
        BRABuffTimeDisplay.setImage(new GreenfootImage(TimeFormat, 20, new Color(100, 255, 100, 40) , new Color(0, 0, 0, 0)));
    }
    //Game
    private void updateGameTimeDisplay()
    {
        int Time = frames/55/* total seconds*/, TotalMinutes = Time/60; // total minutes
        String hours = "0"+(TotalMinutes/60)/* string total hours*/, minutes = "0"+(TotalMinutes%60)/* string remaining minutes*/, seconds = "0"+(Time%60)/* string remaining seconds*/, hrs = hours.substring(hours.length()-2)/* hour output string*/, mins = minutes.substring(minutes.length()-2)/* minutes output string*/, secs = seconds.substring(seconds.length()-2)/* seconds output string*/, TimeFormat = "Time: "+hrs+"hrs "+mins+"mins "+secs+"secs"; //Preview: Time: 52462hrs 28mins 16secs
        GameTimeDisplay.setImage(new GreenfootImage(TimeFormat, 20, new Color(113, 0, 255, 255), new Color(0, 0, 0, 0)));
    }
    
    //Minigame stuff
    //For timing the appearance of the Minigame
    private void updateCooldownDisplay()
    {
        int Time = Cframes/55;
        String minutes = "0"+(Time/60)/* string remaining minutes*/, seconds = "0"+(Time%60)/* string remaining seconds*/, mins = minutes.substring(minutes.length()-2)/* minutes output string*/, secs = seconds.substring(seconds.length()-2)/* seconds output string*/, TimeFormat = "Minigame countdown: "+mins+"mins "+secs+"secs"; //Preview: Minigame countdown: 56mins 27secs
        Cooldown.setImage(new GreenfootImage(TimeFormat, 20, new Color(113, 25, 255, 255), new Color(0, 0, 0, 0)));
    }
    //For choosing and calling out the Minigame
    private void Minigame()
    {
        if (pip != null && pip.getWorld() != null) return; // will not add new pip if one is already in world
        minor = null;
        switch (Greenfoot.getRandomNumber(3))
        {
            case 0: if (!getObjects(Taihei.class).isEmpty()) minor = new Minigame1(); break;
            case 1: if (!getObjects(Bomba.class).isEmpty()) minor = new Minigame2(); break;
            case 2: if (!getObjects(Ebina.class).isEmpty()) minor = new Minigame3(); break;
            case 3: if (!getObjects(Alex.class).isEmpty()) minor = new Minigame4(); break;
        }
        if (minor != null)
        {
            pip = new PIP(minor, new Class[] {});
            pip.setActiveState(true);
            addObject(pip, 690, 110);
        }
    }
    private void setCharacterIncomeDisplay()
    {
        if (SelectedCharacter != null){CharacterYenIncomeDisplay.setImage(new GreenfootImage(SelectedCharacter+CharacterYenIncome, 20, new Color(100, 255, 100, 40) , new Color(0, 0, 0, 0)));}
        else CharacterYenIncomeDisplay.setImage(new GreenfootImage(SelectedCharacter, 20, new Color(100, 255, 100, 40) , new Color(0, 0, 0, 0)));
    }
}
1st minigame world class code:
import greenfoot.*;
public class Minigame1 extends World
{
    public Minigame1()
    {
        super(20, 10, 30);
        // setBackground
        GreenfootImage bg = new GreenfootImage("sand2.jpg");
        bg.scale(getCellSize(), getCellSize());
        setBackground(bg);
        StartGame();
    }
    public void StartGame()
    {
        // add actor to world
        addObject(new MiniTaihei(), 0, 8);
        addObject(new MiniHikari(), 1, 9);
        addObject(new MiniKirie(), (1 + Greenfoot.getRandomNumber(19)), (Greenfoot.getRandomNumber(9)));
        int randX = 0, randY = 0;
        for (int i=0; i<=15;)
        {
            while (randX == 0 || !getObjectsAt(randX, randY, Actor.class).isEmpty())
            {
                randX = (1 + Greenfoot.getRandomNumber(19));
                randY = (Greenfoot.getRandomNumber(9));
            }
            addObject(new Wall(), randX, randY);
            i++;
        }
    }
}
2nd Minigame world class code:
import greenfoot.*;
import java.util.ArrayList;
public class Minigame3 extends World
{   
    //Actors to be in the world
    private Actor ShadowPoseChoice;
    public Minigame3()
    { 
        //world size and back ground set up
        super(600, 400, 1);
        ArrayList<String> imageNums = new ArrayList<String>();
        for (int i=1; i<6; i++) imageNums.add(""+i); // lists numbers of images
        ArrayList<String> shadowNums = new ArrayList<String>(); // for numbers of 3 picked images
        for (int i=0; i<3; i++) // loop to choose and list 3 different random image numbers
        {
            int rand = Greenfoot.getRandomNumber(imageNums.size());
            shadowNums.add(imageNums.remove(rand)); // transfer one random image number between lists
        }
        int rand = Greenfoot.getRandomNumber(shadowNums.size()); // randomly select a choice pose image number
        for (int i=0; i<3; i++)
        {
            Actor actor = new SimpleActor();
            actor.setImage("UmarunShadowPose"+shadowNums.get(i)+".png");
            actor.getImage().scale(100, 100);
            addObject(actor, 120+180*i, 133);
            if (rand == i)
            {
                ShadowPoseChoice = actor;
                Actor poseChoice = new SimpleActor();
                poseChoice.setImage("UmarunPose"+shadowNums.get(i)+".png");
                addObject(poseChoice, 300, 266);
                poseChoice.getImage().scale(100, 100);
            }
        }
    }
    public void act()
    {
        if (Greenfoot.mouseClicked(ShadowPoseChoice))
        {
            removeObjects(getObjects(Actor.class));
            // add yen here
        }
        else if (Greenfoot.mouseClicked(null) && Greenfoot.getMouseInfo().getActor() != null)
        {
            removeObjects(getObjects(Actor.class));
        }
    }
    
}
3rd Minigame world class code:
import greenfoot.*;
public class Minigame4 extends World
{
    public Ground ground = new Ground(), ground2 = new Ground(), ground3 = new Ground(), ground4 = new Ground(), ground5 = new Ground(), ground6 = new Ground(), ground7 = new Ground(), ground8 = new Ground();
    public MiniUmaru HamsterUmaru = new MiniUmaru();
    public SimpleActor Nope = new SimpleActor();
    int SX = 0, SY = 0;
    public Minigame4()
    {
        super(1200, 675, 1);
        GreenfootImage bg = new GreenfootImage("sky.jpg");
        bg.scale(2000, 800);
        setBackground(bg);
        switch(Greenfoot.getRandomNumber(3))
        {
            case 0:terrain1();HamsterUmaru.TerrainUsed = "Terrain 1"; break;
            case 1:terrain2();HamsterUmaru.TerrainUsed = "Terrain 2"; break;
            case 2:terrain3();HamsterUmaru.TerrainUsed = "Terrain 3"; break;
            case 3:terrain4();HamsterUmaru.TerrainUsed = "Terrain 4"; break;
        }
        prepare();
    }


    public void act()
    {
        
    }

    private void terrain1()
    {
        Ground ground9 = new Ground(), ground10 = new Ground();
        ShortGround shortground = new ShortGround(), shortground2 = new ShortGround(), shortground3 = new ShortGround(), shortground4 = new ShortGround(), shortground5 = new ShortGround(), shortground6 = new ShortGround(), shortground7 = new ShortGround(), shortground8 = new ShortGround(), shortground9 = new ShortGround(), shortground10 = new ShortGround(), shortground11 = new ShortGround(), shortground12 = new ShortGround();
        ReturnToStart returntostart = new ReturnToStart(), returntostart2 = new ReturnToStart(), returntostart3 = new ReturnToStart(), returntostart4 = new ReturnToStart(), returntostart5 = new ReturnToStart(), returntostart6 = new ReturnToStart(), returntostart7 = new ReturnToStart();
        addObject(HamsterUmaru,99,487);
        addObject(ground9,102,549);
        addObject(ground10,701,254);
        addObject(ground,85,675);
        addObject(ground2,245,675);
        addObject(ground3,405,675);
        addObject(ground4,565,675);
        addObject(ground5,725,675);
        addObject(ground6,885,675);
        addObject(ground7,1045,675);
        addObject(ground8,1205,675);
        addObject(shortground,323,457);
        addObject(shortground2,179,367);
        addObject(shortground3,48,289);
        addObject(shortground4,359,254);
        addObject(shortground5,509,321);
        addObject(shortground6,196,193);
        addObject(shortground7,887,190);
        addObject(shortground8,1034,140);
        addObject(shortground9,1135,244);
        addObject(shortground10,1004,459);
        addObject(shortground11,849,471);
        addObject(shortground12,677,469);
        addObject(returntostart,612,444);
        addObject(returntostart2,612,369);
        addObject(returntostart3,777,267);
        addObject(returntostart4,612,294);
        addObject(returntostart5,703,267);
        addObject(returntostart6,860,223);
        addObject(returntostart7,935,223);
        returntostart3.turn(90);
        returntostart5.turn(90);
        returntostart6.turn(90);
        returntostart7.turn(90);
    }

    private void terrain2()
    {
        Ground ground9 = new Ground(), ground10 = new Ground(), ground11 = new Ground(), ground12 = new Ground();
        ShortGround shortground = new ShortGround(), shortground2 = new ShortGround(), shortground3 = new ShortGround(), shortground4 = new ShortGround(), shortground5 = new ShortGround(), shortground6 = new ShortGround(), shortground7 = new ShortGround(), shortground8 = new ShortGround(), shortground9 = new ShortGround(), shortground10 = new ShortGround(), shortground11 = new ShortGround(), shortground12 = new ShortGround(), shortground13 = new ShortGround();
        ReturnToStart returntostart = new ReturnToStart(), returntostart2 = new ReturnToStart(), returntostart3 = new ReturnToStart(), returntostart4 = new ReturnToStart();
        addObject(HamsterUmaru,1084,493);
        addObject(ground,85,675);
        addObject(ground2,245,675);
        addObject(ground3,405,675);
        addObject(ground4,565,675);
        addObject(ground5,725,675);
        addObject(ground6,885,675);
        addObject(ground7,1045,675);
        addObject(ground8,1205,675);
        addObject(ground9,1083,551);
        addObject(ground10,447,515);
        addObject(ground11,431,157);
        addObject(ground12,865,109);
        addObject(shortground,883,527);
        addObject(shortground2,737,445);
        addObject(shortground3,591,356);
        addObject(shortground4,236,501);
        addObject(shortground5,115,398);
        addObject(shortground6,239,295);
        addObject(shortground7,74,212);
        addObject(shortground8,242,139);
        addObject(shortground9,647,134);
        addObject(shortground10,1088,137);
        addObject(shortground11,1162,296);
        addObject(shortground12,975,351);
        addObject(shortground13,808,277);
        addObject(returntostart,381,541);
        addObject(returntostart2,456,541);
        addObject(returntostart3,531,541);
        addObject(returntostart4,774,140);
        returntostart.turn(90);
        returntostart2.turn(90);
        returntostart3.turn(90);
    }

    private void terrain3()
    {
        ShortGround shortground = new ShortGround(), shortground2 = new ShortGround(), shortground3 = new ShortGround(), shortground4 = new ShortGround(), shortground5 = new ShortGround(), shortground6 = new ShortGround(), shortground7 = new ShortGround(), shortground8 = new ShortGround(), shortground9 = new ShortGround(), shortground10 = new ShortGround(), shortground11 = new ShortGround(), shortground12 = new ShortGround(), shortground13 = new ShortGround(), shortground14 = new ShortGround(), shortground15 = new ShortGround(), shortground16 = new ShortGround(), shortground17 = new ShortGround(), shortground18 = new ShortGround();
        ReturnToStart returntostart = new ReturnToStart(), returntostart2 = new ReturnToStart(), returntostart3 = new ReturnToStart(), returntostart4 = new ReturnToStart(), returntostart5 = new ReturnToStart(), returntostart6 = new ReturnToStart(), returntostart7 = new ReturnToStart(), returntostart8 = new ReturnToStart();
        addObject(HamsterUmaru,104,527);
        addObject(ground,85,675);
        addObject(ground2,245,675);
        addObject(ground3,405,675);
        addObject(ground4,565,675);
        addObject(ground5,725,675);
        addObject(ground6,885,675);
        addObject(ground7,1045,675);
        addObject(ground8,1205,675);
        addObject(shortground,108,579);
        addObject(shortground2,60,303);
        addObject(shortground3,264,490);
        addObject(shortground4,155,400);
        addObject(shortground5,223,230);
        addObject(shortground6,120,115);
        addObject(shortground7,285,60);
        addObject(shortground8,429,506);
        addObject(shortground9,534,380);
        addObject(shortground10,809,353);
        addObject(shortground11,925,476);
        addObject(shortground12,1034,261);
        addObject(shortground13,919,142);
        addObject(shortground14,1086,85);
        addObject(shortground15,659,406);
        addObject(shortground16,1090,403);
        addObject(shortground17,775,80);
        addObject(shortground18,615,80);
        addObject(returntostart,347,419);
        addObject(returntostart2,765,518);
        addObject(returntostart3,527,36);
        addObject(returntostart4,527,111);
        addObject(returntostart5,785,153);
        addObject(returntostart6,710,153);
        addObject(returntostart7,635,153);
        addObject(returntostart8,560,153);
        returntostart.getImage().scale(8,450);
        returntostart2.getImage().scale(8,250);
        returntostart5.turn(90);
        returntostart6.turn(90);
        returntostart7.turn(90);
        returntostart8.turn(90);
    }
    public void terrain4()
    {
        ShortGround shortground = new ShortGround(), shortground2 = new ShortGround(), shortground3 = new ShortGround(), shortground4 = new ShortGround(), shortground5 = new ShortGround(), shortground6 = new ShortGround(), shortground7 = new ShortGround(), shortground8 = new ShortGround(), shortground9 = new ShortGround(), shortground10 = new ShortGround(), shortground11 = new ShortGround(), shortground12 = new ShortGround(), shortground13 = new ShortGround();
        ReturnToStart returntostart = new ReturnToStart(), returntostart2 = new ReturnToStart(), returntostart3 = new ReturnToStart(), returntostart4 = new ReturnToStart();
        Ground ground9 = new Ground();
        addObject(HamsterUmaru,97,502);
        addObject(ground,85,675);
        addObject(ground2,245,675);
        addObject(ground3,405,675);
        addObject(ground4,565,675);
        addObject(ground5,725,675);
        addObject(ground6,885,675);
        addObject(ground7,1045,675);
        addObject(ground8,1205,675);
        addObject(ground9,93,569);
        addObject(shortground,284,463);
        addObject(shortground2,180,388);        
        addObject(shortground3,71,325);        
        addObject(shortground4,179,235);        
        addObject(shortground5,302,217);       
        addObject(shortground6,433,164);       
        addObject(shortground7,570,164);
        addObject(shortground8,711,164);
        addObject(shortground9,841,164);
        addObject(shortground10,1023,455);
        addObject(shortground11,903,507);
        addObject(shortground12,761,445);
        addObject(shortground13,595,493);
        addObject(returntostart,500,200);
        addObject(returntostart2,903,299);
        addObject(returntostart3,640,200);
        addObject(returntostart4,780,200);
        returntostart.turn(90);
        returntostart2.turn(90);              
        returntostart3.turn(90);
        returntostart4.turn(90);
    }
    public void prepare(){}
}
nccb nccb

2018/5/3

#
From glancing over the code, I don't think you have a memory leak (where you progressively allocate more objects but they stay around). I think you are probably just operating at the limit of the default heap size -- Minigame4 in particular is quite expensive with its large background image, and GifImage I think also takes a bunch of RAM as I think it may keep each frame individually? If you find your greenfoot installation (C:\Program Files (x86)\Greenfoot, usually) and look in the lib directory, there is a file greenfoot.defs. If you find the line beginning "bluej.vm.args=" then you can add a parameter to the end to increase heap space: -Xmx1G So where the old line said:
bluej.vm.args=-Dawt.useSystemAAFontSettings=on -XX:MaxGCPauseMillis=50
Change it to:
bluej.vm.args=-Dawt.useSystemAAFontSettings=on -XX:MaxGCPauseMillis=50 -Xmx1G
(Currently, Greenfoot uses a 32-bit JVM which does not support a max heap size beyond about 1.4G -- at some point we will probably switch to a 64-bit JVM which will allow larger sizes still.)
danpost danpost

2018/5/3

#
This, no doubt, is that you have too many large images existing at one time. Your main world alone is 1400x675, which is like 4 to 6 times bigger than an average sized world. Then, each frame of the Gif animation is also that size. Then you have the background of the mini-games, with the Minigame4 background being almost as large. Then you have the animation image set for Umaru and possibly (unknown) for HamsterUmaru. It is not clear how you are handling the images of the other actors. It may be possible to free up a bit of memory with them, but we would have to go through them one class at a time; however, I do not think you would be able to free enough to avoid the errors that way.
Ticker175 Ticker175

2018/5/3

#
use an array it will most likely solve all ur memory problems and make ur code simpler =) for creating your minigame worlds
Lavenger Lavenger

2018/5/3

#
nccb wrote...
If you find your greenfoot installation (C:\Program Files (x86)\Greenfoot, usually) and look in the lib directory, there is a file greenfoot.defs. If you find the line beginning "bluej.vm.args=" then you can add a parameter to the end to increase heap space: -Xmx1G So where the old line said:
bluej.vm.args=-Dawt.useSystemAAFontSettings=on -XX:MaxGCPauseMillis=50
Change it to:
bluej.vm.args=-Dawt.useSystemAAFontSettings=on -XX:MaxGCPauseMillis=50 -Xmx1G
Thanks ^^ this has solved the issue of it running out of space
You need to login to post a reply.